1 #!/nix/var/nix/profiles/per-user/marc/profile/bin/bash
2 # needing bash because of < <( .. ) below
3 # author Marc Weber Th 17. Jul 00:58:14 CEST 2008
5 # TODO: integrate http://thread.gmane.org/gmane.comp.version-control.git/89644 somehow
8 me="git-test-merge" # name of script
10 cont=".git/$me/continue"
12 [ -f "$tmp" ] && rm "$tmp"
13 COMMIT_MESSAGE=" auto merge MERGE - warning, this branch will be rebased, don't base your work on this branch"
15 failmessage="!! git-test-merge failed, log : \`$tmp'\n"
16 trap 'echo -en "$failmessage"' EXIT;
21 if egrep -l '^<<<<<<<|^>>>>>>>' "$f" &> /dev/null; then
31 while let $(( $# > 0 )); do
32 echo "* merging with $1 ";
33 git merge -m "${COMMIT_MESSAGE/MERGE/$name}" "$1" >> "$tmp" 2>&1 \
35 grep ' does not point to a commit' "$tmp" && { echo ' ^^^^^^^^^^^^ '; exit 1; }
36 echo "probably merge conflicts, have they all been resolved by git-rerere ?"
38 echo -n "checking $f .. "
39 if conflicted "$f"; then
40 echo -e "\n >> \`$f' contains unresolved conflicts"
41 echo "$name" > "$cont"; echo "$@" >> "$cont"
47 [ -n "$conflicted" ] && {
48 echo "resolve conflicts, run $me c to continue"
49 echo " unmerged files will be git-added automatically"
52 done < <( git status | sed -n 's/#\s*unmerged:\s*\(.*\)/\1/p' )
53 # commit ourselves.. and continue
55 git commit -m "${COMMIT_MESSAGE/MERGE/$name}" >> "$tmp" 2>&1
64 set -x; gittestmerge "$@";;
67 conflicted "$f" || { echo " \`$f' still contains conflicts, resolve them and continue, exiting"; failmessage=; exit 1; }
68 git add "$f" >> "$tmp" 2>&1
69 done < <( git status | sed -n 's/#\s*unmerged:\s*\(.*\)/\1/p' )
70 cat $cont | { read name; read x; set $x --; }
74 git config --get rerere.enabled >>/dev/null || {
75 echo ">> git rerere is disabled, maybe you want to enable it using the following command"
76 echo "# git config rerere.enabled 1"
79 if [ "$names" == "" ]; then
80 names=$(fst "$(git config -l | sed -n "s/$me\\.\\([^=]*\\).*/\\1/p")")
84 for name in $names; do
85 echo -e "\nupdating merge $name"
86 set -- `git config --get "$me.$name"`
87 git checkout "$1" >> "$tmp" 2>&1 || {
88 grep 'error: you need to resolve your current index first' "$tmp" && { echo ' ^^^^^^^^^^^^ '; exit 1; }
90 git branch -f "$name" "$1" >> "$tmp" 2>&1; shift # setting it to the first branch, could be another one
91 git checkout "$name" >> "$tmp" 2>&1
93 echo "* merging using octopus"
94 git merge -s octopus -m "${COMMIT_MESSAGE/MERGE/$name based on $@}" "$@" >> "$tmp" 2>&1 \
96 grep ' - not something we can merge' "$tmp" && { echo '^^^^^^^^^^^^ '; exit 1; }
97 echo "octopus merge failed, resetting, using git merge multiple times .."
98 git reset --hard >> "$tmp" 2>&1
105 IFS=, git config "$me.$name" "$*"
109 IFS=, git config "$me.$name" "`git config --get "$me.$name"` $*"
112 git config -l | sed -n "s/$me\\.//p"
115 git-test-merge usage:
117 git-test-merge (s or set) name branch1 branch2 branch3
119 git-test-merge (a or add) name b1 b2
120 adds branches b1 b2 to merge name
121 git-test-merge (l or list) shows all defined merge sets
123 git-test-merge (u or update) list of names
124 if you omit the list of names the first entry will be updated
126 git-test-merge (c or continue) will continue merge (this name only)
128 update name will create a new branch called name by merging
129 branch1, branch2, branch3
130 If you commit to branch1 and you want the the merge
131 to be based on the last commit, run update again
133 if your first arg is (d or debug) set -x will be used.
138 gittestmerge "$@"; # on failure script will exit with trap