Snapshot after 1.2.0 release
[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= USE= USED=
55                 for H in $HH
56                 do
57                         I=$(($I+1))
58                         case " $ans " in
59                         *' '$I' '*)
60                                 USE="$USE$H "
61                                 USED="$USED,$H"
62                                 ;;
63                         *)
64                                 UNUSE="$UNUSE$H "
65                                 ;;
66                         esac
67                 done
68                 USED=`expr "$USED" : ',\(.*\)'`
69                 git pull -n . $USE || exit
70                 # git merge -n "Merge $USED" pu $USE || exit
71                 HH=$UNUSE
72         done
73         exit
74         ;;
75 esac
76
77 for H
78 do
79 #       (IFS=",$IFS"; git merge -n "Merge $H" pu $H) || exit
80         (IFS=",$IFS"; git pull -n . $H) || exit
81 done
82
83 (IFS=",$IFS"; git show-branch master $* pu `git rev-parse --short $ORIG_HEAD`)