Re: [PATCH] git-rebase--interactive.sh: add config option for custom instruction format

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Michael,

On 2015-06-11 03:30, Michael Rappazzo wrote:

> 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?

> 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^^^...

> +	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
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]