# [Git 1.7.6.557.gcee4] git stash

5 messages from 2011-08-22 to 2011-08-22. Participants: Hilco Wijbenga, Brandon Casey.
Thread: https://gitlist.dev/t/28186

## Hilco Wijbenga, 2011-08-22 06:01

Subject: [Git 1.7.6.557.gcee4] git stash
Message-ID: <CAE1pOi1D+J5_fmsdhho1FRAipyO3Ri7GS_wy4fTNtCGbatDaDg@mail.gmail.com>
URL: https://gitlist.dev/e/CAE1pOi1D%2BJ5_fmsdhho1FRAipyO3Ri7GS_wy4fTNtCGbatDaDg%40mail.gmail.com

```
Hi David,

I noticed your very timely change to git stash in the current master
branch. I tried it but it doesn't behave as I was expecting/hoping.

hilco@centaur ~/tmp/repo repo$ git --version
git version 1.7.6.557.gcee4
hilco@centaur ~/tmp/repo repo$ git init
Initialized empty Git repository in /home/hilco/tmp/repo/.git/
hilco@centaur ~/tmp/repo repo (master #)$ cat >>.gitignore <<- EOF
>         *.ignore
>         ignore-dir/
> EOF
hilco@centaur ~/tmp/repo repo (master #%)$ mkdir src
hilco@centaur ~/tmp/repo repo (master #%)$ touch file.txt src/code.txt
hilco@centaur ~/tmp/repo repo (master #%)$ git add -A .
hilco@centaur ~/tmp/repo repo (master #)$ git commit -m '1'
[master (root-commit) 0fb4106] 1
 1 files changed, 2 insertions(+), 0 deletions(-)
 create mode 100644 .gitignore
 create mode 100644 file.txt
 create mode 100644 src/code.txt
hilco@centaur ~/tmp/repo repo (master)$ touch file-a.ignore src/file-b.ignore
hilco@centaur ~/tmp/repo repo (master %)$ echo "hello">src/code.txt
hilco@centaur ~/tmp/repo repo (master *%)$ mkdir ignore-dir
hilco@centaur ~/tmp/repo repo (master *%)$ touch
ignore-dir/{file.ignore,file.txt}
hilco@centaur ~/tmp/repo repo (master *%)$ git status
# On branch master
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       modified:   src/code.txt
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       file-a.ignore
#       ignore-dir/
#       src/file-b.ignore
no changes added to commit (use "git add" and/or "git commit -a")
hilco@centaur ~/tmp/repo repo (master *%)$ git stash --no-keep-index --all
Saved working directory and index state WIP on master: 0fb4106 1
HEAD is now at 0fb4106 1
Not removing ignore-dir/
hilco@centaur ~/tmp/repo repo (master $%)$ git status
# On branch master
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       ignore-dir/
nothing added to commit but untracked files present (use "git add" to track)

So it quite explicitly states "Not removing ignore-dir/". How do I
make sure it also stashes the ignore-dir directory?

Cheers,
Hilco

```

## Brandon Casey, 2011-08-22 17:15

Subject: Re: [Git 1.7.6.557.gcee4] git stash
Message-ID: <euT1_KmfLWaxwFqOd8u_Zv-flc6Wr9rvg1tf_39P-YMaH8T-tpKl94WG8yCIAmW0AMLjdqnjA3I2uGRQf9YpY513-Io-lue5aNPuVDv8Qp8@cipher.nrlssc.navy.mil>
URL: https://gitlist.dev/e/euT1_KmfLWaxwFqOd8u_Zv-flc6Wr9rvg1tf_39P-YMaH8T-tpKl94WG8yCIAmW0AMLjdqnjA3I2uGRQf9YpY513-Io-lue5aNPuVDv8Qp8%40cipher.nrlssc.navy.mil
In-Reply-To: <CAE1pOi1D+J5_fmsdhho1FRAipyO3Ri7GS_wy4fTNtCGbatDaDg@mail.gmail.com>

```
On 08/22/2011 01:01 AM, Hilco Wijbenga wrote:
> Hi David,
> 
> I noticed your very timely change to git stash in the current master
> branch. I tried it but it doesn't behave as I was expecting/hoping.

It looks like it is actually creating the stash correctly, but it's
just not deleting the ignored directory.

But, there is a small problem with your command sequence...

> hilco@centaur ~/tmp/repo repo$ git --version
> git version 1.7.6.557.gcee4
> hilco@centaur ~/tmp/repo repo$ git init
> Initialized empty Git repository in /home/hilco/tmp/repo/.git/
> hilco@centaur ~/tmp/repo repo (master #)$ cat >>.gitignore <<- EOF
>>         *.ignore
>>         ignore-dir/
>> EOF
> hilco@centaur ~/tmp/repo repo (master #%)$ mkdir src
> hilco@centaur ~/tmp/repo repo (master #%)$ touch file.txt src/code.txt
> hilco@centaur ~/tmp/repo repo (master #%)$ git add -A .
> hilco@centaur ~/tmp/repo repo (master #)$ git commit -m '1'
> [master (root-commit) 0fb4106] 1
>  1 files changed, 2 insertions(+), 0 deletions(-)
>  create mode 100644 .gitignore
>  create mode 100644 file.txt
>  create mode 100644 src/code.txt
> hilco@centaur ~/tmp/repo repo (master)$ touch file-a.ignore src/file-b.ignore
> hilco@centaur ~/tmp/repo repo (master %)$ echo "hello">src/code.txt
> hilco@centaur ~/tmp/repo repo (master *%)$ mkdir ignore-dir
> hilco@centaur ~/tmp/repo repo (master *%)$ touch
> ignore-dir/{file.ignore,file.txt}
> hilco@centaur ~/tmp/repo repo (master *%)$ git status
> # On branch master
> # Changes not staged for commit:
> #   (use "git add <file>..." to update what will be committed)
> #   (use "git checkout -- <file>..." to discard changes in working directory)
> #
> #       modified:   src/code.txt
> #
> # Untracked files:
> #   (use "git add <file>..." to include in what will be committed)
> #
> #       file-a.ignore
> #       ignore-dir/
> #       src/file-b.ignore
          ^^^^^^^^^^^^^^^^^
Why are these entries here?

> no changes added to commit (use "git add" and/or "git commit -a")

if your .gitignore file looks like this:

   $ cat .gitignore
   *.ignore
   ignore-dir/

then why are those items showing up under "Untracked files:" in the call
to git status above?  /methinks something is wrong with your .gitignore
file.  It doesn't matter in this case, since --all will cause stash to
stash the untracked files regardless of whether they are ignored.

> hilco@centaur ~/tmp/repo repo (master *%)$ git stash --no-keep-index --all
> Saved working directory and index state WIP on master: 0fb4106 1
> HEAD is now at 0fb4106 1
> Not removing ignore-dir/
> hilco@centaur ~/tmp/repo repo (master $%)$ git status
> # On branch master
> # Untracked files:
> #   (use "git add <file>..." to include in what will be committed)
> #
> #       ignore-dir/
> nothing added to commit but untracked files present (use "git add" to track)

Also, in the future it would be nicer if you provided your list of
commands separately, at the beginning, linked together with &&.
This makes it easier to copy/paste into my terminal, rather than
having to extract the commands out from within the body.
Like this (slightly simplified):

   git --version &&
   git init &&
   cat <<-\EOF >.gitignore &&
	*.ignore
	ignore-dir/
	EOF
   mkdir src &&
   touch file.txt src/code.txt &&
   git add . &&
   git commit -m 'initial commit' &&
   touch file-a.ignore src/file-b.ignore &&
   echo "hello" >src/code.txt &&
   mkdir ignore-dir &&
   touch ignore-dir/{file.ignore,file.txt} &&
   git status &&
   git stash --all &&
   git status || echo 'FAILURE'

> So it quite explicitly states "Not removing ignore-dir/".

That message is from git-clean, and it is the real problem.

> How do I
> make sure it also stashes the ignore-dir directory?

It actually did stash the ignore-dir, it just didn't remove it from
the working directory at the end.  Try deleting the ignore-dir by
hand and then applying the stash, ignore-dir and its content should
be recreated.

Something like this is probably the appropriate fix:

diff --git a/git-stash.sh b/git-stash.sh
index f4e6f05..a2d4b4d 100755
--- a/git-stash.sh
+++ b/git-stash.sh
@@ -240,7 +240,7 @@ save_stash () {
                test "$untracked" = "all" && CLEAN_X_OPTION=-x || CLEAN_X_OPTION
                if test -n "$untracked"
                then
-                       git clean --force --quiet $CLEAN_X_OPTION
+                       git clean --force --quiet -d $CLEAN_X_OPTION
                fi
 
                if test "$keep_index" = "t" && test -n $i_tree

Needs tests.

-Brandon

```

## Hilco Wijbenga, 2011-08-22 18:43

Subject: Re: [Git 1.7.6.557.gcee4] git stash
Message-ID: <CAE1pOi2OnHpu+kBj8Z47nb7C-MHFpUMAc8ArG3haWpncEDQ-jA@mail.gmail.com>
URL: https://gitlist.dev/e/CAE1pOi2OnHpu%2BkBj8Z47nb7C-MHFpUMAc8ArG3haWpncEDQ-jA%40mail.gmail.com
In-Reply-To: <euT1_KmfLWaxwFqOd8u_Zv-flc6Wr9rvg1tf_39P-YMaH8T-tpKl94WG8yCIAmW0AMLjdqnjA3I2uGRQf9YpY513-Io-lue5aNPuVDv8Qp8@cipher.nrlssc.navy.mil>

```
On 22 August 2011 10:15, Brandon Casey
<brandon.casey.ctr@nrlssc.navy.mil> wrote:
> On 08/22/2011 01:01 AM, Hilco Wijbenga wrote:
>> Hi David,
>>
>> I noticed your very timely change to git stash in the current master
>> branch. I tried it but it doesn't behave as I was expecting/hoping.
>
> It looks like it is actually creating the stash correctly, but it's
> just not deleting the ignored directory.
>
> But, there is a small problem with your command sequence...
>
>> hilco@centaur ~/tmp/repo repo$ git --version
>> git version 1.7.6.557.gcee4
>> hilco@centaur ~/tmp/repo repo$ git init
>> Initialized empty Git repository in /home/hilco/tmp/repo/.git/
>> hilco@centaur ~/tmp/repo repo (master #)$ cat >>.gitignore <<- EOF
>>>         *.ignore
>>>         ignore-dir/
>>> EOF
>> hilco@centaur ~/tmp/repo repo (master #%)$ mkdir src
>> hilco@centaur ~/tmp/repo repo (master #%)$ touch file.txt src/code.txt
>> hilco@centaur ~/tmp/repo repo (master #%)$ git add -A .
>> hilco@centaur ~/tmp/repo repo (master #)$ git commit -m '1'
>> [master (root-commit) 0fb4106] 1
>>  1 files changed, 2 insertions(+), 0 deletions(-)
>>  create mode 100644 .gitignore
>>  create mode 100644 file.txt
>>  create mode 100644 src/code.txt
>> hilco@centaur ~/tmp/repo repo (master)$ touch file-a.ignore src/file-b.ignore
>> hilco@centaur ~/tmp/repo repo (master %)$ echo "hello">src/code.txt
>> hilco@centaur ~/tmp/repo repo (master *%)$ mkdir ignore-dir
>> hilco@centaur ~/tmp/repo repo (master *%)$ touch
>> ignore-dir/{file.ignore,file.txt}
>> hilco@centaur ~/tmp/repo repo (master *%)$ git status
>> # On branch master
>> # Changes not staged for commit:
>> #   (use "git add <file>..." to update what will be committed)
>> #   (use "git checkout -- <file>..." to discard changes in working directory)
>> #
>> #       modified:   src/code.txt
>> #
>> # Untracked files:
>> #   (use "git add <file>..." to include in what will be committed)
>> #
>> #       file-a.ignore
>> #       ignore-dir/
>> #       src/file-b.ignore
>          ^^^^^^^^^^^^^^^^^
> Why are these entries here?

My bad. I had a script that ran the commands but I decided to try run
them on the CL so I copy-pasted them. That changed the tabs to spaces
and ruined .gitignore.

>> no changes added to commit (use "git add" and/or "git commit -a")
>
> if your .gitignore file looks like this:
>
>   $ cat .gitignore
>   *.ignore
>   ignore-dir/
>
> then why are those items showing up under "Untracked files:" in the call
> to git status above?  /methinks something is wrong with your .gitignore
> file.  It doesn't matter in this case, since --all will cause stash to
> stash the untracked files regardless of whether they are ignored.
>
>> hilco@centaur ~/tmp/repo repo (master *%)$ git stash --no-keep-index --all
>> Saved working directory and index state WIP on master: 0fb4106 1
>> HEAD is now at 0fb4106 1
>> Not removing ignore-dir/
>> hilco@centaur ~/tmp/repo repo (master $%)$ git status
>> # On branch master
>> # Untracked files:
>> #   (use "git add <file>..." to include in what will be committed)
>> #
>> #       ignore-dir/
>> nothing added to commit but untracked files present (use "git add" to track)
>
> Also, in the future it would be nicer if you provided your list of
> commands separately, at the beginning, linked together with &&.
> This makes it easier to copy/paste into my terminal, rather than
> having to extract the commands out from within the body.
> Like this (slightly simplified):
>
>   git --version &&
>   git init &&
>   cat <<-\EOF >.gitignore &&
>        *.ignore
>        ignore-dir/
>        EOF
>   mkdir src &&
>   touch file.txt src/code.txt &&
>   git add . &&
>   git commit -m 'initial commit' &&
>   touch file-a.ignore src/file-b.ignore &&
>   echo "hello" >src/code.txt &&
>   mkdir ignore-dir &&
>   touch ignore-dir/{file.ignore,file.txt} &&
>   git status &&
>   git stash --all &&
>   git status || echo 'FAILURE'

Noted. Will do.

>> So it quite explicitly states "Not removing ignore-dir/".
>
> That message is from git-clean, and it is the real problem.
>
>> How do I
>> make sure it also stashes the ignore-dir directory?
>
> It actually did stash the ignore-dir, it just didn't remove it from
> the working directory at the end.  Try deleting the ignore-dir by
> hand and then applying the stash, ignore-dir and its content should
> be recreated.
>
> Something like this is probably the appropriate fix:
>
> diff --git a/git-stash.sh b/git-stash.sh
> index f4e6f05..a2d4b4d 100755
> --- a/git-stash.sh
> +++ b/git-stash.sh
> @@ -240,7 +240,7 @@ save_stash () {
>                test "$untracked" = "all" && CLEAN_X_OPTION=-x || CLEAN_X_OPTION
>                if test -n "$untracked"
>                then
> -                       git clean --force --quiet $CLEAN_X_OPTION
> +                       git clean --force --quiet -d $CLEAN_X_OPTION
>                fi
>
>                if test "$keep_index" = "t" && test -n $i_tree
>
> Needs tests.

I just tried it with the extra -d and it all seems to work
beautifully. Should your patch be sent anywhere?

```

## Brandon Casey, 2011-08-22 19:58

Subject: Re: [Git 1.7.6.557.gcee4] git stash
Message-ID: <fbFntd6r8tmN4NcET9Ya3OWDfsrxz1tfPv7GaddGfwwdirG8AgjrG8ARoR2-ZhadzpRI2DU2ZtTGdWAUGJeUZuBXmxWX5eSmT16u5cBjtec@cipher.nrlssc.navy.mil>
URL: https://gitlist.dev/e/fbFntd6r8tmN4NcET9Ya3OWDfsrxz1tfPv7GaddGfwwdirG8AgjrG8ARoR2-ZhadzpRI2DU2ZtTGdWAUGJeUZuBXmxWX5eSmT16u5cBjtec%40cipher.nrlssc.navy.mil
In-Reply-To: <CAE1pOi2OnHpu+kBj8Z47nb7C-MHFpUMAc8ArG3haWpncEDQ-jA@mail.gmail.com>

```
On 08/22/2011 01:43 PM, Hilco Wijbenga wrote:
> On 22 August 2011 10:15, Brandon Casey
> <brandon.casey.ctr@nrlssc.navy.mil> wrote:
>> On 08/22/2011 01:01 AM, Hilco Wijbenga wrote:
>>> Hi David,
>>>
>>> I noticed your very timely change to git stash in the current master
>>> branch. I tried it but it doesn't behave as I was expecting/hoping.
>>
>> It looks like it is actually creating the stash correctly, but it's
>> just not deleting the ignored directory.

>> Something like this is probably the appropriate fix:
>>
>> diff --git a/git-stash.sh b/git-stash.sh
>> index f4e6f05..a2d4b4d 100755
>> --- a/git-stash.sh
>> +++ b/git-stash.sh
>> @@ -240,7 +240,7 @@ save_stash () {
>>                test "$untracked" = "all" && CLEAN_X_OPTION=-x || CLEAN_X_OPTION
>>                if test -n "$untracked"
>>                then
>> -                       git clean --force --quiet $CLEAN_X_OPTION
>> +                       git clean --force --quiet -d $CLEAN_X_OPTION
>>                fi
>>
>>                if test "$keep_index" = "t" && test -n $i_tree
>>
>> Needs tests.
> 
> I just tried it with the extra -d and it all seems to work
> beautifully. Should your patch be sent anywhere?

It needs a couple of tests added to t/t3905-stash-include-untracked.sh
to demonstrate that this functionality works correctly and to ensure
that it doesn't break in the future.

Need tests at least for:

   --all stashes untracked / ignored in subdirectory
   --include-untracked stashes untracked in subdirectory, leaves ignored alone

Do we currently test that stash leaves untracked / ignored alone when
--all or --include-untracked are not supplied?

And it needs a commit message following the guidelines in
Documentation/SubmittingPatches.  Then it can be submitted to this list
using format-patch and send-email.  Interested??? :)  otherwise I'll try
to get to it later tonight.

-Brandon

```

## Hilco Wijbenga, 2011-08-22 20:15

Subject: Re: [Git 1.7.6.557.gcee4] git stash
Message-ID: <CAE1pOi1Et9e1g8cKUPZBykV-Y2-4UMRuxHvcDjRjEg7WxF=i1A@mail.gmail.com>
URL: https://gitlist.dev/e/CAE1pOi1Et9e1g8cKUPZBykV-Y2-4UMRuxHvcDjRjEg7WxF%3Di1A%40mail.gmail.com
In-Reply-To: <fbFntd6r8tmN4NcET9Ya3OWDfsrxz1tfPv7GaddGfwwdirG8AgjrG8ARoR2-ZhadzpRI2DU2ZtTGdWAUGJeUZuBXmxWX5eSmT16u5cBjtec@cipher.nrlssc.navy.mil>

```
On 22 August 2011 12:58, Brandon Casey
<brandon.casey.ctr@nrlssc.navy.mil> wrote:
> On 08/22/2011 01:43 PM, Hilco Wijbenga wrote:
>> On 22 August 2011 10:15, Brandon Casey
>> <brandon.casey.ctr@nrlssc.navy.mil> wrote:
>>> On 08/22/2011 01:01 AM, Hilco Wijbenga wrote:
>>>> Hi David,
>>>>
>>>> I noticed your very timely change to git stash in the current master
>>>> branch. I tried it but it doesn't behave as I was expecting/hoping.
>>>
>>> It looks like it is actually creating the stash correctly, but it's
>>> just not deleting the ignored directory.
>
>>> Something like this is probably the appropriate fix:
>>>
>>> diff --git a/git-stash.sh b/git-stash.sh
>>> index f4e6f05..a2d4b4d 100755
>>> --- a/git-stash.sh
>>> +++ b/git-stash.sh
>>> @@ -240,7 +240,7 @@ save_stash () {
>>>                test "$untracked" = "all" && CLEAN_X_OPTION=-x || CLEAN_X_OPTION
>>>                if test -n "$untracked"
>>>                then
>>> -                       git clean --force --quiet $CLEAN_X_OPTION
>>> +                       git clean --force --quiet -d $CLEAN_X_OPTION
>>>                fi
>>>
>>>                if test "$keep_index" = "t" && test -n $i_tree
>>>
>>> Needs tests.
>>
>> I just tried it with the extra -d and it all seems to work
>> beautifully. Should your patch be sent anywhere?
>
> It needs a couple of tests added to t/t3905-stash-include-untracked.sh
> to demonstrate that this functionality works correctly and to ensure
> that it doesn't break in the future.
>
> Need tests at least for:
>
>   --all stashes untracked / ignored in subdirectory
>   --include-untracked stashes untracked in subdirectory, leaves ignored alone
>
> Do we currently test that stash leaves untracked / ignored alone when
> --all or --include-untracked are not supplied?
>
> And it needs a commit message following the guidelines in
> Documentation/SubmittingPatches.  Then it can be submitted to this list
> using format-patch and send-email.  Interested??? :)  otherwise I'll try
> to get to it later tonight.

Interested? Sure. Do I have the time? Unfortunately not. I'm
overworked as it is. :-( Well, maybe in the weekend. But this would be
a major operation for me because it's all new.

```
