Automatically remove already merged ones.
[git.git] / PU
1 #!/bin/sh
2 #
3 # Rebuild "pu" from topic branches.
4 #
5
6 git-update-index --refresh || exit
7 case "$(git-diff-index --name-status HEAD)" in
8 '')     ;;
9 *)      echo 2>&1 "Local modifications exist."
10         exit 1;;
11 esac
12 git checkout pu &&
13 git reset --hard master &&
14 ORIG_HEAD=`git rev-parse ORIG_HEAD` || exit
15 LF='
16 '
17
18 case "$#" in
19 0)
20         # interactive ;-)
21         shift
22         HH=`cd .git/refs/heads && find -type f |
23         sed -e 's/^\.\///' \
24             -e '/^naster$/d' -e '/^master$/d' -e '/^maint$/d' -e '/^pu$/d'`
25         while test "$HH"
26         do
27                 I=0
28                 echo "0: done"
29                 NHH=
30                 for H in $HH
31                 do
32                         HSHA1=`git-rev-parse --verify $H` || continue
33                         MB=`git-show-branch --merge-base pu $HSHA1`
34                         case "$LF$MB$LF" in
35                         *"$LF$HSHA1$LF"*) continue ;; # already merged.
36                         esac
37                         I=$(($I+1))
38                         echo -n "$I: "
39                         git-show-branch $H
40                         NHH="${NHH}$H "
41                 done
42                 case "$I" in
43                 0)
44                         break ;;
45                 esac
46                 HH=$NHH
47                 echo -n "Merge which ones (0 to finish)? "
48                 read ans
49                 case "$ans" in
50                 '' | 0)
51                         break ;;
52                 esac
53                 I=0
54                 UNUSE=
55                 USE=
56                 for H in $HH
57                 do
58                         I=$(($I+1))
59                         case " $ans " in
60                         *' '$I' '*)
61                                 USE="$USE$H "
62                                 ;;
63                         *)
64                                 UNUSE="$UNUSE$H "
65                                 ;;
66                         esac
67                 done
68                 git pull -n . $USE || exit
69                 HH=$UNUSE
70         done
71         exit
72         ;;
73 esac
74
75 for H
76 do
77         (IFS=",$IFS"; git pull -n . $H) || exit
78 done
79
80 (IFS=",$IFS"; git show-branch master pu $* $ORIG_HEAD)