2587df669b
The script uses "git show -s" to display the title of the merge commit being studied, without explicitly disabling the pager, which is not a safe thing to do in a script. For example, when the pager is set to "less" with "-SF" options (-S tells the pager not to fold lines but allow horizontal scrolling to show the overly long lines, -F tells the pager not to wait if the output in its entirety is shown on a single page), and the title of the merge commit is longer than the width of the terminal, the pager will wait until the end-user tells it to quit after showing the single line. Explicitly disable the pager with this "git show" invocation to fix this. The command uses the "--pretty=format:..." format, which adds LF in between each pair of commits it outputs, which means that the label for the merge being learned from will be followed by the next message on the same line. "--pretty=tformat:..." is what we should instead, which adds LF after each commit, or a more modern way to spell it, i.e. "--format=...". This existing breakage becomes easier to see, now we no longer use the pager. Signed-off-by: Junio C Hamano <gitster@pobox.com>
103 lines
1.6 KiB
Bash
Executable File
103 lines
1.6 KiB
Bash
Executable File
#!/bin/sh
|
|
# Copyright (c) 2008, Nanako Shiraishi
|
|
# Prime rerere database from existing merge commits
|
|
|
|
me=rerere-train
|
|
USAGE=$(cat <<-EOF
|
|
usage: $me [--overwrite] <rev-list-args>
|
|
|
|
-h, --help show the help
|
|
-o, --overwrite overwrite any existing rerere cache
|
|
EOF
|
|
)
|
|
|
|
SUBDIRECTORY_OK=Yes
|
|
|
|
overwrite=0
|
|
|
|
while test $# -gt 0
|
|
do
|
|
opt="$1"
|
|
case "$opt" in
|
|
-h|--help)
|
|
echo "$USAGE"
|
|
exit 0
|
|
;;
|
|
-o|--overwrite)
|
|
overwrite=1
|
|
shift
|
|
break
|
|
;;
|
|
--)
|
|
shift
|
|
break
|
|
;;
|
|
*)
|
|
break
|
|
;;
|
|
esac
|
|
done
|
|
|
|
# Overwrite or help options are not valid except as first arg
|
|
for opt in "$@"
|
|
do
|
|
case "$opt" in
|
|
-h|--help)
|
|
echo "$USAGE"
|
|
exit 0
|
|
;;
|
|
-o|--overwrite)
|
|
echo "$USAGE"
|
|
exit 0
|
|
;;
|
|
esac
|
|
done
|
|
|
|
. "$(git --exec-path)/git-sh-setup"
|
|
require_work_tree
|
|
cd_to_toplevel
|
|
|
|
# Remember original branch
|
|
branch=$(git symbolic-ref -q HEAD) ||
|
|
original_HEAD=$(git rev-parse --verify HEAD) || {
|
|
echo >&2 "Not on any branch and no commit yet?"
|
|
exit 1
|
|
}
|
|
|
|
mkdir -p "$GIT_DIR/rr-cache" || exit
|
|
|
|
git rev-list --parents "$@" |
|
|
while read commit parent1 other_parents
|
|
do
|
|
if test -z "$other_parents"
|
|
then
|
|
# Skip non-merges
|
|
continue
|
|
fi
|
|
git checkout -q "$parent1^0"
|
|
if git merge $other_parents >/dev/null 2>&1
|
|
then
|
|
# Cleanly merges
|
|
continue
|
|
fi
|
|
if test $overwrite = 1
|
|
then
|
|
git rerere forget .
|
|
fi
|
|
if test -s "$GIT_DIR/MERGE_RR"
|
|
then
|
|
git --no-pager show -s --format="Learning from %h %s" "$commit"
|
|
git rerere
|
|
git checkout -q $commit -- .
|
|
git rerere
|
|
fi
|
|
git reset -q --hard # Might nuke untracked files...
|
|
done
|
|
|
|
if test -z "$branch"
|
|
then
|
|
git checkout "$original_HEAD"
|
|
else
|
|
git checkout "${branch#refs/heads/}"
|
|
fi
|