git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] stash create: Add --include-untracked and --all option to stash create

From
Junio C Hamano <gitster@pobox.com>
Date
Jun 27, 2014, 17:37 UTC
Message-ID
<xmqqionm2qzv.fsf@gitster.dls.corp.google.com>
In-Reply-To
<1403856479-37421-1-git-send-email-shigeta@kanamei.co.jp>
shigeta@kanamei.co.jp writes:
> From: Kazumasa Shigeta <shigeta@kanamei.co.jp>
>
> The --include-untracked option acts like the normal "git stash save --include-untracked --all" but it does not change anything in working directory.
> It is inconvenient stash create does not have --include-untracked option however stash save has --include-untracked option.
Please wrap long lines.
> It fails when using message that start with dash. It is not compatible with now.

I cannot quite parse this. What do you exactly mean by "It is not compatible with now"? Do you mean "with this patch, we break backward compatibility" and if so in what way?

Show 12 quoted lines
> diff --git a/git-stash.sh b/git-stash.sh
> index 4798bcf..d636651 100755
> --- a/git-stash.sh
> +++ b/git-stash.sh
> @@ -57,8 +57,35 @@ clear_stash () {
>  }
>  
>  create_stash () {
> -	stash_msg="$1"
> -	untracked="$2"
> +    stash_msg=
> +    untracked=
Broken indentation here?  We indent with tabs, not runs of spaces.
Show 52 quoted lines
> +	while test $# != 0
> +	do
> +		case "$1" in
> +		-u|--include-untracked)
> +			untracked=untracked
> +			;;
> +		-a|--all)
> +			untracked=all
> +			;;
> +		--)
> +			shift
> +			break
> +			;;
> +		-*)
> +			option="$1"
> +			eval_gettextln "error: unknown option for 'stash create': \$option
> +       To provide a message, use git stash create -- '\$option'"
> +			exit 1
> +			;;
> +		*)
> +			break
> +			;;
> +		esac
> +		shift
> +	done
> +	stash_msg="$*"
>  
>  	git update-index -q --refresh
>  	if no_changes
> @@ -260,8 +287,25 @@ save_stash () {
>  	fi
>  	test -f "$GIT_DIR/logs/$ref_stash" ||
>  		clear_stash || die "$(gettext "Cannot initialize stash")"
> +    untracked_opt=
> +    case "$untracked" in
> +		untracked)
> +			untracked_opt="--include-untracked"
> +			break
> +			;;
> +		all)
> +			untracked_opt="--all"
> +			break
> +			;;
> +    esac
> +
> +	if test -z "$untracked_opt"
> +	then
> +		create_stash  -- "$stash_msg"
> +	else
> +		create_stash "$untracked_opt" -- "$stash_msg"
> +	fi
> -	create_stash "$stash_msg" $untracked
Wouldn't it suffice to do:
	create_stash ${untracked_opt:+"$untracked_opt"} -- "$stash_msg"
without if/then/else/fi?
Show 12 quoted lines
> diff --git a/t/t3907-stash-create-include-untracked.sh b/t/t3907-stash-create-include-untracked.sh
> new file mode 100755
> index 0000000..c28ed0f
> --- /dev/null
> +++ b/t/t3907-stash-create-include-untracked.sh
> @@ -0,0 +1,286 @@
> +#!/bin/sh
> +#
> +# File:   t3907-stash-create-include-untracked.sh
> +# Author: shigeta
> +#
> +# Created on 2014/05/01, 13:13:15

Please discard the above lines. We can see what file it is in, and "git log" knows who wrote it when. You are only risking them to become obsolete and/or irrelevant over time without adding any real value.

Don't we have existing test script for "stash"? If we do, shouldn't this patch be appending test pieces for new mode of operation it introduces to that existing script instead?

Show 9 quoted lines
> +test_description='Test git stash create --include-untracked and --all'
> +
> +. ./test-lib.sh
> +
> +cat > .gitignore <<EOF
> +.gitignore
> +ignored
> +ignored.d/
> +EOF

No SP between redirect operator and the filename. Quote EOF if your here-document does not need any variable interpolation to reduce mental burden from readers. I.e.

	cat >.gitignore <<\EOF
        foo
        bar
        EOF

Also in newer test scripts we try to have as little commands to be executed outside test_expect_success set-up block as possible. The general structure of a new test script (if we do need to add one for this patch, which I doubt) should be along the lines of...

	test_description='...'
        . ./test-lib.sh
	test_expect_success setup '
		the first test piece typically does all the set up &&
		cat >.gitignore <<-\EOF &&
                .gitignore
                ...
                EOF
		other initialisation necessary
	'
        test_expect_success 'explain what this second test checks' '
		piece specific setup &&
		cat >expect <<-\EOF &&
                expected output comes here
                EOF
                do the command >actual &&
                test_cmp expect actual
	'
        test_expect_success 'explain what this third test checks' '
        ...
        test_done
Previous: shigeta@kanamei.co.jp
Message 2 of 2 in “stash create: Add --include-untracked and --all option to stash create”
  1. stash create: Add --include-untracked and --all option to stash createshigeta@kanamei.co.jp, Jun 27, 2014
  2. Junio C HamanoJun 27, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.