git-rebase--interactive.sh: add config option for custom instruction format

A config option 'rebase.instructionFormat' can override the default 'oneline' format of the rebase instruction list. Since the list is parsed using the left, right or boundary mark plus the sha1, they are prepended to the instruction format. Signed-off-by: Michael Rappazzo <rappazzo@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Michael Rappazzo committed Jun 13, 2015 at 12:26 UTC 16cf51c7a2e82f27577bb1bdcdc013c34815803e
4 files changed +50 -3
Documentation/config.txt
+5
@@ -2160,6 +2160,11 @@ rebase.autoStash::
2160 successful rebase might result in non-trivial conflicts.
2161 Defaults to false.
2162
2163 +rebase.instructionFormat
2164 + A format string, as specified in linkgit:git-log[1], to be used for
2165 + the instruction list during an interactive rebase. The format will automatically
2166 + have the long commit hash prepended to the format.
2167 +
2168 receive.advertiseAtomic::
2169 By default, git-receive-pack will advertise the atomic push
2170 capability to its clients. If you don't want to this capability
Documentation/git-rebase.txt
+7
@@ -213,6 +213,9 @@ rebase.autoSquash::
213 rebase.autoStash::
214 If set to true enable '--autostash' option by default.
215
216 +rebase.instructionFormat::
217 + Custom commit list format to use during an '--interactive' rebase.
218 +
219 OPTIONS
220 -------
221 --onto <newbase>::
@@ -359,6 +362,10 @@ default is `--no-fork-point`, otherwise the default is `--fork-point`.
362 Make a list of the commits which are about to be rebased. Let the
363 user edit that list before rebasing. This mode can also be used to
364 split commits (see SPLITTING COMMITS below).
365 ++
366 +The commit list format can be changed by setting the configuration option
367 +rebase.instructionFormat. A customized instruction format will automatically
368 +have the long commit hash prepended to the format.
369
370 -p::
371 --preserve-merges::
git-rebase--interactive.sh
+17 -3
@@ -740,10 +740,15 @@ collapse_todo_ids() {
740 # "pick sha1 fixup!/squash! msg" appears in it so that the latter
741 # comes immediately after the former, and change "pick" to
742 # "fixup"/"squash".
743 +#
744 +# Note that if the config has specified a custom instruction format
745 +# each log message will be re-retrieved in order to normalize the
746 +# autosquash arrangement
747 rearrange_squash () {
748 # extract fixup!/squash! lines and resolve any referenced sha1's
749 while read -r pick sha1 message
750 do
751 + test -z "${format}" || message=$(git log -n 1 --format="%s" ${sha1})
752 case "$message" in
753 "squash! "*|"fixup! "*)
754 action="${message%%!*}"
@@ -785,6 +790,7 @@ rearrange_squash () {
790 *" $sha1 "*) continue ;;
791 esac
792 printf '%s\n' "$pick $sha1 $message"
793 + test -z "${format}" || message=$(git log -n 1 --format="%s" ${sha1})
794 used="$used$sha1 "
795 while read -r squash action msg_prefix msg_content
796 do
@@ -802,8 +808,13 @@ rearrange_squash () {
808 case "$message" in "$msg_content"*) emit=1;; esac ;;
809 esac
810 if test $emit = 1; then
805 - real_prefix=$(echo "$msg_prefix" | sed "s/,/! /g")
806 - printf '%s\n' "$action $squash ${real_prefix}$msg_content"
811 + if test -n "${format}"
812 + then
813 + msg_content=$(git log -n 1 --format="${format}" ${squash})
814 + else
815 + msg_content="$(echo "$msg_prefix" | sed "s/,/! /g")$msg_content"
816 + fi
817 + printf '%s\n' "$action $squash $msg_content"
818 used="$used$squash "
819 fi
820 done <"$1.sq"
@@ -977,7 +988,10 @@ else
988 revisions=$onto...$orig_head
989 shortrevisions=$shorthead
990 fi
980 -git rev-list $merges_option --pretty=oneline --reverse --left-right --topo-order \
991 +format=$(git config --get rebase.instructionFormat)
992 +# the 'rev-list .. | sed' requires %m to parse; the instruction requires %H to parse
993 +git rev-list $merges_option --format="%m%H ${format:-%s}" \
994 + --reverse --left-right --topo-order \
995 $revisions ${restrict_revision+^$restrict_revision} | \
996 sed -n "s/^>//p" |
997 while read -r sha1 rest
t/t3415-rebase-autosquash.sh
+21
@@ -250,4 +250,25 @@ test_expect_success 'squash! fixup!' '
250 test_auto_fixup_fixup squash fixup
251 '
252
253 +test_expect_success 'autosquash with custom inst format' '
254 + git reset --hard base &&
255 + git config --add rebase.instructionFormat "[%an @ %ar] %s" &&
256 + echo 2 >file1 &&
257 + git add -u &&
258 + test_tick &&
259 + git commit -m "squash! $(git rev-parse --short HEAD^)" &&
260 + echo 1 >file1 &&
261 + git add -u &&
262 + test_tick &&
263 + git commit -m "squash! $(git log -n 1 --format=%s HEAD~2)" &&
264 + git tag final-squash-instFmt &&
265 + test_tick &&
266 + git rebase --autosquash -i HEAD~4 &&
267 + git log --oneline >actual &&
268 + test_line_count = 3 actual &&
269 + git diff --exit-code final-squash-instFmt &&
270 + test 1 = "$(git cat-file blob HEAD^:file1)" &&
271 + test 2 = $(git cat-file commit HEAD^ | grep squash | wc -l)
272 +'
273 +
274 test_done