TODO: ident/filter is in.
[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
13 case "$1" in
14 --continue)
15         shift
16         ;;
17 *)
18         git checkout pu &&
19         git reset --hard master || exit
20 esac
21 ORIG_HEAD=`git rev-parse ORIG_HEAD` || exit
22 LF='
23 '
24
25 case "$#" in
26 0)
27         # interactive ;-)
28         shift
29         HH=`cd .git/refs/heads && find -type f |
30         sed -e 's/^\.\///' \
31             -e '/^naster$/d' -e '/^master$/d' -e '/^maint$/d' -e '/^pu$/d'`
32         while test "$HH"
33         do
34                 I=0
35                 echo "0: done"
36                 NHH=
37                 for H in $HH
38                 do
39                         HSHA1=`git-rev-parse --verify $H` || continue
40                         MB=`git-show-branch --merge-base pu $HSHA1`
41                         case "$LF$MB$LF" in
42                         *"$LF$HSHA1$LF"*) continue ;; # already merged.
43                         esac
44                         I=$(($I+1))
45                         echo -n "$I: "
46                         git-show-branch $H
47                         NHH="${NHH}$H "
48                 done
49                 case "$I" in
50                 0)
51                         break ;;
52                 esac
53                 HH=$NHH
54                 echo -n "Merge which ones (0 to finish)? "
55                 read ans
56                 case "$ans" in
57                 '' | 0)
58                         break ;;
59                 esac
60                 I=0
61                 UNUSE= USE= USED=
62                 for H in $HH
63                 do
64                         I=$(($I+1))
65                         case " $ans " in
66                         *' '$I' '*)
67                                 USE="$USE$H "
68                                 USED="$USED,$H"
69                                 ;;
70                         *)
71                                 UNUSE="$UNUSE$H "
72                                 ;;
73                         esac
74                 done
75                 USED=`expr "$USED" : ',\(.*\)'`
76                 git pull -n . $USE || exit
77                 # git merge -n "Merge $USED" pu $USE || exit
78                 HH=$UNUSE
79         done
80         exit
81         ;;
82 esac
83
84 for H
85 do
86 #       (IFS=",$IFS"; git merge -n "Merge $H" pu $H) || exit
87         (IFS=",$IFS"; git pull -n . $H) || exit
88 done
89
90 (IFS=",$IFS"; git show-branch master $* pu `git rev-parse --short $ORIG_HEAD`)