lib-rebase: Allow comments and blank lines to be added to the rebase script
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH v2 1/3 lib-rebase: Provide clearer debugging info about what the editor did
(For testing "rebase -i"): Output the "rebase -i" command script before and after the edits, to make it clearer what the editor did.
--- t/lib-rebase.sh | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-)
t/lib-rebase.sh +3 -2
@@ -29,6 +29,7 @@ test -z "$EXPECT_COUNT" || test -z "$FAKE_LINES" && exit grep -v '^#' < "$1" > "$1".tmp rm -f "$1" +echo 'rebase -i script before editing:' cat "$1".tmp action=pick for line in $FAKE_LINES; do
@@ -36,12 +37,12 @@ for line in $FAKE_LINES; do squash|fixup|edit|reword) action="$line";; *) - echo sed -n "${line}s/^pick/$action/p" - sed -n "${line}p" < "$1".tmp sed -n "${line}s/^pick/$action/p" < "$1".tmp >> "$1" action=pick;; esac done +echo 'rebase -i script after editing:' +cat "$1" EOF test_set_editor "$(pwd)/fake-editor.sh"
Signature · 1 line
1.6.6.140.ga53ad
Re: [PATCHv2 1/3] lib-rebase: Provide clearer debugging info about what the editor did
Very nice; thanks.
PATCH v2 2/3 lib-rebase: Allow comments and blank lines to be added to the rebase script
In reply to a message not in the archive(For testing "rebase -i"): Support new action types in $FAKE_LINES to allow comments and blank lines to be added to the "rebase -i" command list.
--- t/lib-rebase.sh | 21 ++++++++++++++++----- 1 files changed, 16 insertions(+), 5 deletions(-)
t/lib-rebase.sh +16 -5
@@ -5,13 +5,20 @@ # - override the commit message with $FAKE_COMMIT_MESSAGE, # - amend the commit message with $FAKE_COMMIT_AMEND # - check that non-commit messages have a certain line count with $EXPECT_COUNT -# - rewrite a rebase -i script with $FAKE_LINES in the form +# - rewrite a rebase -i script as directed by $FAKE_LINES. +# $FAKE_LINES consists of a sequence of words separated by spaces. +# The following word combinations are possible: # -# "[<lineno1>] [<lineno2>]..." +# "<lineno>" -- add a "pick" line with the SHA1 taken from the +# specified line. # -# If a line number is prefixed with "squash", "fixup", "edit", or -# "reword", the respective line's command will be replaced with the -# specified one. +# "<cmd> <lineno>" -- add a line with the specified command +# ("squash", "fixup", "edit", or "reword") and the SHA1 taken +# from the specified line. +# +# "#" -- Add a comment line. +# +# ">" -- Add a blank line. set_fake_editor () { echo "#!$SHELL_PATH" >fake-editor.sh
@@ -36,6 +43,10 @@ for line in $FAKE_LINES; do case $line in squash|fixup|edit|reword) action="$line";; + "#") + echo '# comment' >> "$1";; + ">") + echo >> "$1";; *) sed -n "${line}s/^pick/$action/p" < "$1".tmp >> "$1" action=pick;;
Signature · 1 line
1.6.6.140.ga53ad
PATCH v2 3/3 rebase-i: Ignore comments and blank lines in peek_next_command
In reply to a message not in the archivePreviously, blank lines and/or comments within a series of squash/fixup commands would confuse "git rebase -i" into thinking that the series was finished. It would therefore require the user to edit the commit message for the squash/fixup commits seen so far. Then, after continuing, it would ask the user to edit the commit message again.
Ignore comments and blank lines within a group of squash/fixup commands, allowing them to be processed in one go.
--- git-rebase--interactive.sh | 2 +- t/t3404-rebase-interactive.sh | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletions(-)
git-rebase--interactive.sh +1 -1
@@ -340,7 +340,7 @@ make_squash_message () { } peek_next_command () { - sed -n "1s/ .*$//p" < "$TODO" + sed -n -e "/^#/d" -e "/^$/d" -e "s/ .*//p" -e "q" < "$TODO" } do_next () {
t/t3404-rebase-interactive.sh +24 -0
@@ -265,6 +265,30 @@ test_expect_success 'squash and fixup generate correct log messages' ' git branch -D squash-fixup ' +test_expect_success 'squash ignores comments' ' + git checkout -b skip-comments E && + base=$(git rev-parse HEAD~4) && + FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="# 1 # squash 2 # squash 3 # squash 4 #" \ + EXPECT_HEADER_COUNT=4 \ + git rebase -i $base && + test $base = $(git rev-parse HEAD^) && + test 1 = $(git show | grep ONCE | wc -l) && + git checkout to-be-rebased && + git branch -D skip-comments +' + +test_expect_success 'squash ignores blank lines' ' + git checkout -b skip-blank-lines E && + base=$(git rev-parse HEAD~4) && + FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="> 1 > squash 2 > squash 3 > squash 4 >" \ + EXPECT_HEADER_COUNT=4 \ + git rebase -i $base && + test $base = $(git rev-parse HEAD^) && + test 1 = $(git show | grep ONCE | wc -l) && + git checkout to-be-rebased && + git branch -D skip-blank-lines +' + test_expect_success 'squash works as expected' ' for n in one two three four do
Signature · 1 line
1.6.6.140.ga53ad
v2 cover rebase-i: Ignore comments and blank lines among squash/fixup commands
In reply to a message not in the archiveHere is v2 of the patch (now patch series) for making "rebase -i" ignore comments and blank lines while it is processing blocks of squash/fixup commands.
Please note that this version applies to "next", not "master", because it depends on some changes to t/t3404-rebase-interactive.sh that were made in mh/rebase-fixup. (This dependency is superficial and could be removed if necessary.)
The first patch in this series is not essential to the functionality but I found it useful when debugging the tests.
Michael Haggerty (3):
lib-rebase: Provide clearer debugging info about what the editor did
lib-rebase: Allow comments and blank lines to be added to the rebase
script
rebase-i: Ignore comments and blank lines in peek_next_command
git-rebase--interactive.sh | 2 +- t/lib-rebase.sh | 26 +++++++++++++++++++------- t/t3404-rebase-interactive.sh | 24 ++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 8 deletions(-)
Re: [PATCHv2 0/3] rebase-i: Ignore comments and blank lines among squash/fixup commands
Hi,
Quoted 3 lines · Michael Haggerty
Here is v2 of the patch (now patch series) for making "rebase -i" ignore comments and blank lines while it is processing blocks of squash/fixup commands.
Me likee.
Thanks,
Dscho