Fix rebasing-merge script
[msysgit.git] / share / msysGit / rebasing-merge.sh
blob49ec68cfb0c5764a0a258ea0ad789a2aac87f5cf
1 #!/bin/sh
3 TO=junio/next
5 TODO_EXTRA="$(git rev-parse --git-dir)/todo-extra"
7 # Rebase 'devel' on top of 'junio/next', the merging the old state of
8 # 'devel' with the merge strategy 'ours' to enable a fast-forward.
10 THIS="$(cd "$(dirname "$0")" && pwd)/$(basename "$0")" &&
11 cd /git &&
12 case "$(git rev-parse --symbolic-full-name HEAD)" in
13 refs/heads/devel)
14 test "$(git rev-parse HEAD)" = "$(git rev-parse origin/devel)" ||
15 test "$(git rev-parse devel@{1})" = "$(git rev-parse origin/devel)" || {
16 echo "Your 'devel' is not up-to-date!" >&2
17 exit 1
19 ;; # okay
20 HEAD) ;; # okay
22 echo "Not on 'devel'!" >&2
23 exit 1
25 esac
27 # Find old rebasing merge, if any
29 rm -f "$TODO_EXTRA"
31 MERGE=$(git rev-list --parents $TO.. | sed -n 's/ .* .*//p' | head -n 1)
32 if test "$(git rev-parse $MERGE:)" = "$(git rev-parse "$MERGE^:")"
33 then
34 ORIG_HEAD=$(git rev-parse HEAD) &&
35 # Find prior merges to $TO
36 EXCLUDE=$(git rev-list --parents $TO..$MERGE^ |
37 sed -n 's/^\([^ ]*\) .* .*/^\1/p') &&
38 # Get commits from previous rebasing merge
39 git rev-list --pretty=oneline --abbrev-commit --abbrev=7 --reverse \
40 --no-merges $TO..$MERGE^ $EXCLUDE |
41 sed 's/^/pick /' > "$TODO_EXTRA" &&
42 TMP_EDITOR="$(git rev-parse --git-dir)/rebasing-editor.sh" &&
43 cat > "$TMP_EDITOR" << EOF &&
44 #!/bin/sh
45 case "\$1" in
46 */git-rebase-todo)
47 cat "\$1" >> "$TODO_EXTRA" &&
48 mv "$TODO_EXTRA" "\$1"
49 esac &&
50 exec "$(git var GIT_EDITOR)" "\$@"
51 EOF
52 if GIT_EDITOR="$TMP_EDITOR" git rebase -i $MERGE --onto $TO
53 then
54 git merge -s ours -m "Rebasing merge to $TO" $ORIG_HEAD
55 else
56 cat << EOF
58 After the rebase, call 'git merge -s ours $ORIG_HEAD' manually
59 EOF
62 else
63 git rebase -i $TO