From 356b8ecff101e3f763619d74f344ede3204c7991 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Sat, 7 Jan 2017 03:23:19 -0500 Subject: rebase--interactive: count squash commits above 10 correctly We generate the squash commit message incrementally running a sed script once for each commit. It parses "This is a combination of commits" from the first line of the existing message, adds one to , and uses the result as the number of our current message. Since f2d17068fd (i18n: rebase-interactive: mark comments of squash for translation, 2016-06-17), the first line may be localized, and sed uses a pretty liberal regex, looking for: /^#.*([0-9][0-9]*)/ The "[0-9][0-9]*" tries to match double digits, but it doesn't quite work. The first ".*" is greedy, so if you have: This is a combination of 10 commits. it will eat up "This is a combination of 1", leaving "0" to match the first "[0-9]" digit, and then skipping the optional match of "[0-9]*". As a result, the count resets every 10 commits, and a 15-commit squash would end up as: # This is a combination of 5 commits. # This is the 1st commit message: ... # This is the commit message #2: ... and so on .. # This is the commit message #10: ... # This is the commit message #1: ... # This is the commit message #2: ... etc, up to 5 ... We can fix this by making the ".*" less greedy. Instead of depending on ".*?" working portably, we can just limit the match to non-digit characters, which accomplishes the same thing. Reported-by: Brandon Tolsch Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- git-rebase--interactive.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'git-rebase--interactive.sh') diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh index ca994c5c5..4bca73c94 100644 --- a/git-rebase--interactive.sh +++ b/git-rebase--interactive.sh @@ -416,7 +416,7 @@ update_squash_messages () { if test -f "$squash_msg"; then mv "$squash_msg" "$squash_msg".bak || exit count=$(($(sed -n \ - -e "1s/^$comment_char.*\([0-9][0-9]*\).*/\1/p" \ + -e "1s/^$comment_char[^0-9]*\([0-9][0-9]*\).*/\1/p" \ -e "q" < "$squash_msg".bak)+1)) { printf '%s\n' "$comment_char $(eval_ngettext \ -- cgit v1.2.1