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

2014-06-27 Thread Junio C Hamano
shig...@kanamei.co.jp writes:

> From: Kazumasa Shigeta 
>
> 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?

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

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

> diff --git a/t/t3907-stash-create-include-untracked.sh 
> b/t/t3907-stash-create-include-untracked.sh
> new file mode 100755
> index 000..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?

> +test_description='Test git stash create --include-untracked and --all'
> +
> +. ./test-lib.sh
> +
> +cat > .gitignore < +.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
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo in

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

2014-06-27 Thread shigeta
From: Kazumasa Shigeta 

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.
It fails when using message that start with dash. It is not compatible with now.

Signed-off-by: Kazumasa Shigeta 
---
 Documentation/git-stash.txt   |   4 +-
 git-stash.sh  |  52 +-
 t/t3907-stash-create-include-untracked.sh | 286 ++
 3 files changed, 336 insertions(+), 6 deletions(-)
 create mode 100755 t/t3907-stash-create-include-untracked.sh

diff --git a/Documentation/git-stash.txt b/Documentation/git-stash.txt
index 375213f..7ff9ce6 100644
--- a/Documentation/git-stash.txt
+++ b/Documentation/git-stash.txt
@@ -16,7 +16,7 @@ SYNOPSIS
 'git stash' [save [-p|--patch] [-k|--[no-]keep-index] [-q|--quiet]
 [-u|--include-untracked] [-a|--all] []]
 'git stash' clear
-'git stash' create []
+'git stash' create [-u|--include-untracked] [-a|--all] []
 'git stash' store [-m|--message ] [-q|--quiet] 
 
 DESCRIPTION
@@ -148,7 +148,7 @@ drop [-q|--quiet] []::
`` must be a valid stash log reference of the form
`stash@{}`.
 
-create::
+create [-u|--include-untracked] [-a|--all] []::
 
Create a stash (which is a regular commit object) and return its
object name, without storing it anywhere in the ref namespace.
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=
+
+   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
store_stash -m "$stash_msg" -q $w_commit ||
die "$(gettext "Cannot save the current status")"
say Saved working directory and index state "$stash_msg"
@@ -584,7 +628,7 @@ clear)
;;
 create)
shift
-   create_stash "$*" && echo "$w_commit"
+   create_stash "$@" && echo "$w_commit"
;;
 store)
shift
diff --git a/t/t3907-stash-create-include-untracked.sh 
b/t/t3907-stash-create-include-untracked.sh
new file mode 100755
index 000..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
+
+test_description='Test git stash create --include-untracked and --all'
+
+. ./test-lib.sh
+
+cat > .gitignore < file &&
+   git add file &&
+   test_tick &&
+   git commit -m initial &&
+   echo 2 > file &&
+   git add file &&
+   echo 3 > file &&
+   test_tick &&
+   echo 1 > file2 &&
+   echo 1 > HEAD &&
+   mkdir untracked &&
+   echo untracked >untracked/untracked &&
+   echo ignored > ignored &&
+   mkdir ignored.d &&
+   echo ignored >ignored.d/untracked
+   STASH_ID_U=$(git stash create -u message1 message2 message3) &&
+   test_tick &&
+   STASH_ID__INCLUDE_UNTRACKED=$(git stash create --include-untracked 
message1 message2 message3) &&
+   test_tick &&
+   STASH_ID_A=$(git stash create -a message1 message2 message3) &&
+   test_tick &&
+   STASH_ID__ALL=$(git stash create --all message1 message2 message3)
+'
+
+cat