config.txt: move user.* to a separate file
[git/debian.git] / contrib / rerere-train.sh
blobeeee45dd341b25d51b7497c4def555c4133c4267
1 #!/bin/sh
2 # Copyright (c) 2008, Nanako Shiraishi
3 # Prime rerere database from existing merge commits
5 me=rerere-train
6 USAGE=$(cat <<-EOF
7 usage: $me [--overwrite] <rev-list-args>
9 -h, --help show the help
10 -o, --overwrite overwrite any existing rerere cache
11 EOF
14 SUBDIRECTORY_OK=Yes
16 overwrite=0
18 while test $# -gt 0
20 opt="$1"
21 case "$opt" in
22 -h|--help)
23 echo "$USAGE"
24 exit 0
26 -o|--overwrite)
27 overwrite=1
28 shift
29 break
31 --)
32 shift
33 break
36 break
38 esac
39 done
41 # Overwrite or help options are not valid except as first arg
42 for opt in "$@"
44 case "$opt" in
45 -h|--help)
46 echo "$USAGE"
47 exit 0
49 -o|--overwrite)
50 echo "$USAGE"
51 exit 0
53 esac
54 done
56 . "$(git --exec-path)/git-sh-setup"
57 require_work_tree
58 cd_to_toplevel
60 # Remember original branch
61 branch=$(git symbolic-ref -q HEAD) ||
62 original_HEAD=$(git rev-parse --verify HEAD) || {
63 echo >&2 "Not on any branch and no commit yet?"
64 exit 1
67 mkdir -p "$GIT_DIR/rr-cache" || exit
69 git rev-list --parents "$@" |
70 while read commit parent1 other_parents
72 if test -z "$other_parents"
73 then
74 # Skip non-merges
75 continue
77 git checkout -q "$parent1^0"
78 if git merge $other_parents >/dev/null 2>&1
79 then
80 # Cleanly merges
81 continue
83 if test $overwrite = 1
84 then
85 git rerere forget .
87 if test -s "$GIT_DIR/MERGE_RR"
88 then
89 git show -s --pretty=format:"Learning from %h %s" "$commit"
90 git rerere
91 git checkout -q $commit -- .
92 git rerere
94 git reset -q --hard
95 done
97 if test -z "$branch"
98 then
99 git checkout "$original_HEAD"
100 else
101 git checkout "${branch#refs/heads/}"