Re: [PATCH] git-rebase--interactive.sh: add config option for custom instruction format
- From
Johannes Schindelin <johannes.schindelin@gmx.de>
- Date
- Jun 11, 2015, 13:40 UTC
- Message-ID
- <dabb4e8e3a864b26c002e9ef966bdf85@www.dscho.org>
- In-Reply-To
- <1433986244-76038-2-git-send-email-rappazzo@gmail.com>
Hi Michael,
On 2015-06-11 03:30, Michael Rappazzo wrote:
Show 18 quoted lines
> diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
> index dc3133f..6d14315 100644
> --- a/git-rebase--interactive.sh
> +++ b/git-rebase--interactive.sh
> @@ -740,10 +740,19 @@ collapse_todo_ids() {
> # "pick sha1 fixup!/squash! msg" appears in it so that the latter
> # comes immediately after the former, and change "pick" to
> # "fixup"/"squash".
> +#
> +# Note that if the config has specified a custom instruction format
> +# each log message will be re-retrieved in order to normalize the
> +# autosquash arrangement
> rearrange_squash () {
> # extract fixup!/squash! lines and resolve any referenced sha1's
> - while read -r pick sha1 message
> + while read -r pick sha1 todo_message
> do
> + message=${todo_message}Why not just leave the `read -r pick sha1 message` as-is and simply write
# For "autosquash": test -z "$format" || message="$(git log -n 1 --format="%s" $sha1)"
here?
Show 18 quoted lines
> diff --git a/t/t3415-rebase-autosquash.sh b/t/t3415-rebase-autosquash.sh > index 41370ab..1ef96eb 100755 > --- a/t/t3415-rebase-autosquash.sh > +++ b/t/t3415-rebase-autosquash.sh > @@ -250,4 +250,37 @@ test_expect_success 'squash! fixup!' ' > test_auto_fixup_fixup squash fixup > ' > > +test_expect_success 'autosquash with custom inst format matching on sha1' ' > + git reset --hard base && > + git config --add rebase.instructionFormat "[%an @ %ar] %s" && > + echo 1 >file1 && > + git add -u && > + test_tick && > + git commit -m "squash! $(git rev-parse --short HEAD^)" && > + git tag final-shasquash-instFmt && > + test_tick && > + git rebase --autosquash -i HEAD^^^ &&
We usually write HEAD~3 instead of HEAD^^^...
Show 23 quoted lines
> + git log --oneline >actual && > + test_line_count = 3 actual && > + git diff --exit-code final-shasquash-instFmt && > + test 1 = "$(git cat-file blob HEAD^:file1)" && > + test 1 = $(git cat-file commit HEAD^ | grep squash | wc -l) > +' > + > +test_expect_success 'autosquash with custom inst format matching on comment' ' > + git reset --hard base && > + git config --add rebase.instructionFormat "[%an @ %ar] %s" && > + echo 1 >file1 && > + git add -u && > + test_tick && > + git commit -m "squash! $(git log -n 1 --format=%s HEAD^)" && > + git tag final-comment-squash-instFmt && > + test_tick && > + git rebase --autosquash -i HEAD^^^ && > + git log --oneline >actual && > + test_line_count = 3 actual && > + git diff --exit-code final-comment-squash-instFmt && > + test 1 = "$(git cat-file blob HEAD^:file1)" && > + test 1 = $(git cat-file commit HEAD^ | grep squash | wc -l) > +'
That is copied almost verbatim, except for the commit message. The code would be easier to maintain if it did not repeat so much code e.g. by refactoring out a function that takes the commit message as a parameter.
Ciao, Johannes