modify git-completion.bash so git PS1 works correctly
[git/mingw/4msysgit/gitPS1fix.git] / contrib / rerere-train.sh
blob2cfe1b936b0feef1bd40947ce6ab249f62a6ad55
1 #!/bin/sh
2 # Copyright (c) 2008, Nanako Shiraishi
3 # Prime rerere database from existing merge commits
5 me=rerere-train
6 USAGE="$me rev-list-args"
8 SUBDIRECTORY_OK=Yes
9 OPTIONS_SPEC=
10 . git-sh-setup
11 require_work_tree
12 cd_to_toplevel
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
21 mkdir -p "$GIT_DIR/rr-cache" || exit
23 git rev-list --parents "$@" |
24 while read commit parent1 other_parents
26 if test -z "$other_parents"
27 then
28 # Skip non-merges
29 continue
31 git checkout -q "$parent1^0"
32 if git merge $other_parents >/dev/null 2>&1
33 then
34 # Cleanly merges
35 continue
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
44 git reset -q --hard
45 done
47 if test -z "$branch"
48 then
49 git checkout "$original_HEAD"
50 else
51 git checkout "${branch#refs/heads/}"