Merge branch 'da/difftool'
[git] / contrib / rerere-train.sh
1 #!/bin/sh
2 # Copyright (c) 2008, Nanako Shiraishi
3 # Prime rerere database from existing merge commits
4
5 me=rerere-train
6 USAGE="$me rev-list-args"
7
8 SUBDIRECTORY_OK=Yes
9 OPTIONS_SPEC=
10 . $(git --exec-path)/git-sh-setup
11 require_work_tree
12 cd_to_toplevel
13
14 # Remember original branch
15 branch=$(git symbolic-ref -q HEAD) ||
16 original_HEAD=$(git rev-parse --verify HEAD) || {
17         echo >&2 "Not on any branch and no commit yet?"
18         exit 1
19 }
20
21 mkdir -p "$GIT_DIR/rr-cache" || exit
22
23 git rev-list --parents "$@" |
24 while read commit parent1 other_parents
25 do
26         if test -z "$other_parents"
27         then
28                 # Skip non-merges
29                 continue
30         fi
31         git checkout -q "$parent1^0"
32         if git merge $other_parents >/dev/null 2>&1
33         then
34                 # Cleanly merges
35                 continue
36         fi
37         if test -s "$GIT_DIR/MERGE_RR"
38         then
39                 git show -s --pretty=format:"Learning from %h %s" "$commit"
40                 git rerere
41                 git checkout -q $commit -- .
42                 git rerere
43         fi
44         git reset -q --hard
45 done
46
47 if test -z "$branch"
48 then
49         git checkout "$original_HEAD"
50 else
51         git checkout "${branch#refs/heads/}"
52 fi