# git add --intent-to-add + git stash "Cannot save the current worktree state"

6 messages from 2019-01-03 to 2019-01-10. Participants: Anthony Sottile, Johannes Schindelin, Junio C Hamano.
Thread: https://gitlist.dev/t/50147

## Anthony Sottile, 2019-01-03 20:46

Subject: git add --intent-to-add + git stash "Cannot save the current worktree state"
Message-ID: <CA+dzEBmh4LdN-XFS9y9YKrDMzV_7+QpDzBA2uv9Xi80PgR5NTQ@mail.gmail.com>
URL: https://gitlist.dev/e/CA%2BdzEBmh4LdN-XFS9y9YKrDMzV_7%2BQpDzBA2uv9Xi80PgR5NTQ%40mail.gmail.com

```
Minimal reproduction

ˋˋˋ
git init t
git -C t commit --allow-empty -m 'initial commit'
touch t/a
git -C t add --intent-to-add a
git -C t stash
ˋˋˋ

ˋˋˋ
+ git init t
Initialized empty Git repository in /private/tmp/t/t/.git/
+ git -C t commit --allow-empty -m 'initial commit'
[master (root-commit) 858132e] initial commit
+ touch t/a
+ git -C t add --intent-to-add a
+ git -C t stash
error: Entry 'a' not uptodate. Cannot merge.
Cannot save the current worktree state
ˋˋˋ

Anthony

```

## Johannes Schindelin, 2019-01-09 18:24

Subject: Re: git add --intent-to-add + git stash "Cannot save the current worktree state"
Message-ID: <nycvar.QRO.7.76.6.1901091922300.41@tvgsbejvaqbjf.bet>
URL: https://gitlist.dev/e/nycvar.QRO.7.76.6.1901091922300.41%40tvgsbejvaqbjf.bet
In-Reply-To: <CA+dzEBmh4LdN-XFS9y9YKrDMzV_7+QpDzBA2uv9Xi80PgR5NTQ@mail.gmail.com>

```
Hi Anthony,

On Thu, 3 Jan 2019, Anthony Sottile wrote:

> Minimal reproduction
> 
> ˋˋˋ
> git init t
> git -C t commit --allow-empty -m 'initial commit'
> touch t/a
> git -C t add --intent-to-add a
> git -C t stash
> ˋˋˋ
> 
> ˋˋˋ
> + git init t
> Initialized empty Git repository in /private/tmp/t/t/.git/
> + git -C t commit --allow-empty -m 'initial commit'
> [master (root-commit) 858132e] initial commit
> + touch t/a
> + git -C t add --intent-to-add a
> + git -C t stash
> error: Entry 'a' not uptodate. Cannot merge.
> Cannot save the current worktree state
> ˋˋˋ

Apparently it is even worse. On Windows, this reportedly resulted in a
segmentation fault:

https://github.com/git-for-windows/git/issues/2006

Could you cherry-pick the fix of
https://github.com/git-for-windows/git/pull/2008 and see whether it fixes
your use case, too?

Ciao,
Johannes

P.S.: Obviously, if this PR fixes the issue, the corresponding change
should be squashed into the appropriate commit in ps/stash-in-c.

```

## Anthony Sottile, 2019-01-09 18:36

Subject: Re: git add --intent-to-add + git stash "Cannot save the current worktree state"
Message-ID: <CA+dzEBn_-=77ZzfOaS8nVnQkf4rh0Y6TbEknZe6c02cwktrTJg@mail.gmail.com>
URL: https://gitlist.dev/e/CA%2BdzEBn_-%3D77ZzfOaS8nVnQkf4rh0Y6TbEknZe6c02cwktrTJg%40mail.gmail.com
In-Reply-To: <nycvar.QRO.7.76.6.1901091922300.41@tvgsbejvaqbjf.bet>

```
On Wed, Jan 9, 2019 at 10:25 AM Johannes Schindelin
<Johannes.Schindelin@gmx.de> wrote:
>
> Hi Anthony,
>
> On Thu, 3 Jan 2019, Anthony Sottile wrote:
>
> > Minimal reproduction
> >
> > ˋˋˋ
> > git init t
> > git -C t commit --allow-empty -m 'initial commit'
> > touch t/a
> > git -C t add --intent-to-add a
> > git -C t stash
> > ˋˋˋ
> >
> > ˋˋˋ
> > + git init t
> > Initialized empty Git repository in /private/tmp/t/t/.git/
> > + git -C t commit --allow-empty -m 'initial commit'
> > [master (root-commit) 858132e] initial commit
> > + touch t/a
> > + git -C t add --intent-to-add a
> > + git -C t stash
> > error: Entry 'a' not uptodate. Cannot merge.
> > Cannot save the current worktree state
> > ˋˋˋ
>
> Apparently it is even worse. On Windows, this reportedly resulted in a
> segmentation fault:
>
> https://github.com/git-for-windows/git/issues/2006
>
> Could you cherry-pick the fix of
> https://github.com/git-for-windows/git/pull/2008 and see whether it fixes
> your use case, too?
>
> Ciao,
> Johannes
>
> P.S.: Obviously, if this PR fixes the issue, the corresponding change
> should be squashed into the appropriate commit in ps/stash-in-c.

I don't see a `stash.c` in ecbdaf0899161c067986e9d9d564586d4b045d62 --
the patch doesn't appear to apply

`stash` appears to be implemented as `git-stash.sh`

Anthony

```

## Johannes Schindelin, 2019-01-10 15:21

Subject: Re: git add --intent-to-add + git stash "Cannot save the current worktree state"
Message-ID: <nycvar.QRO.7.76.6.1901101620470.41@tvgsbejvaqbjf.bet>
URL: https://gitlist.dev/e/nycvar.QRO.7.76.6.1901101620470.41%40tvgsbejvaqbjf.bet
In-Reply-To: <CA+dzEBn_-=77ZzfOaS8nVnQkf4rh0Y6TbEknZe6c02cwktrTJg@mail.gmail.com>

```
Hi Anthony,

On Wed, 9 Jan 2019, Anthony Sottile wrote:

> On Wed, Jan 9, 2019 at 10:25 AM Johannes Schindelin
> <Johannes.Schindelin@gmx.de> wrote:
> >
> > On Thu, 3 Jan 2019, Anthony Sottile wrote:
> >
> > > Minimal reproduction
> > >
> > > ˋˋˋ
> > > git init t
> > > git -C t commit --allow-empty -m 'initial commit'
> > > touch t/a
> > > git -C t add --intent-to-add a
> > > git -C t stash
> > > ˋˋˋ
> > >
> > > ˋˋˋ
> > > + git init t
> > > Initialized empty Git repository in /private/tmp/t/t/.git/
> > > + git -C t commit --allow-empty -m 'initial commit'
> > > [master (root-commit) 858132e] initial commit
> > > + touch t/a
> > > + git -C t add --intent-to-add a
> > > + git -C t stash
> > > error: Entry 'a' not uptodate. Cannot merge.
> > > Cannot save the current worktree state
> > > ˋˋˋ
> >
> > Apparently it is even worse. On Windows, this reportedly resulted in a
> > segmentation fault:
> >
> > https://github.com/git-for-windows/git/issues/2006
> >
> > Could you cherry-pick the fix of
> > https://github.com/git-for-windows/git/pull/2008 and see whether it fixes
> > your use case, too?
> >
> > P.S.: Obviously, if this PR fixes the issue, the corresponding change
> > should be squashed into the appropriate commit in ps/stash-in-c.
> 
> I don't see a `stash.c` in ecbdaf0899161c067986e9d9d564586d4b045d62 --
> the patch doesn't appear to apply
> 
> `stash` appears to be implemented as `git-stash.sh`

Whoops. I thought that you were on a different Git version, one that
already has the built-in stash. My mistake.

Sorry,
Johannes

```

## Anthony Sottile, 2019-01-10 16:16

Subject: Re: git add --intent-to-add + git stash "Cannot save the current worktree state"
Message-ID: <CA+dzEBnUTybrK-V3xQJmDoNU8wDtuDKhDzKEtCBhFdP=5x3G5Q@mail.gmail.com>
URL: https://gitlist.dev/e/CA%2BdzEBnUTybrK-V3xQJmDoNU8wDtuDKhDzKEtCBhFdP%3D5x3G5Q%40mail.gmail.com
In-Reply-To: <nycvar.QRO.7.76.6.1901101620470.41@tvgsbejvaqbjf.bet>

```
On Thu, Jan 10, 2019 at 7:21 AM Johannes Schindelin
<Johannes.Schindelin@gmx.de> wrote:
>
> Hi Anthony,
>
> On Wed, 9 Jan 2019, Anthony Sottile wrote:
>
> > On Wed, Jan 9, 2019 at 10:25 AM Johannes Schindelin
> > <Johannes.Schindelin@gmx.de> wrote:
> > >
> > > On Thu, 3 Jan 2019, Anthony Sottile wrote:
> > >
> > > > Minimal reproduction
> > > >
> > > > ˋˋˋ
> > > > git init t
> > > > git -C t commit --allow-empty -m 'initial commit'
> > > > touch t/a
> > > > git -C t add --intent-to-add a
> > > > git -C t stash
> > > > ˋˋˋ
> > > >
> > > > ˋˋˋ
> > > > + git init t
> > > > Initialized empty Git repository in /private/tmp/t/t/.git/
> > > > + git -C t commit --allow-empty -m 'initial commit'
> > > > [master (root-commit) 858132e] initial commit
> > > > + touch t/a
> > > > + git -C t add --intent-to-add a
> > > > + git -C t stash
> > > > error: Entry 'a' not uptodate. Cannot merge.
> > > > Cannot save the current worktree state
> > > > ˋˋˋ
> > >
> > > Apparently it is even worse. On Windows, this reportedly resulted in a
> > > segmentation fault:
> > >
> > > https://github.com/git-for-windows/git/issues/2006
> > >
> > > Could you cherry-pick the fix of
> > > https://github.com/git-for-windows/git/pull/2008 and see whether it fixes
> > > your use case, too?
> > >
> > > P.S.: Obviously, if this PR fixes the issue, the corresponding change
> > > should be squashed into the appropriate commit in ps/stash-in-c.
> >
> > I don't see a `stash.c` in ecbdaf0899161c067986e9d9d564586d4b045d62 --
> > the patch doesn't appear to apply
> >
> > `stash` appears to be implemented as `git-stash.sh`
>
> Whoops. I thought that you were on a different Git version, one that
> already has the built-in stash. My mistake.
>
> Sorry,
> Johannes

Oh, is there a more recent version than the one mirrored at
https://github.com/git/git

Anthony

```

## Junio C Hamano, 2019-01-10 17:45

Subject: Re: git add --intent-to-add + git stash "Cannot save the current worktree state"
Message-ID: <xmqqy37s2yqn.fsf@gitster-ct.c.googlers.com>
URL: https://gitlist.dev/e/xmqqy37s2yqn.fsf%40gitster-ct.c.googlers.com
In-Reply-To: <CA+dzEBmh4LdN-XFS9y9YKrDMzV_7+QpDzBA2uv9Xi80PgR5NTQ@mail.gmail.com>

```
Anthony Sottile <asottile@umich.edu> writes:

> Minimal reproduction
>
> ˋˋˋ
> git init t
> git -C t commit --allow-empty -m 'initial commit'
> touch t/a
> git -C t add --intent-to-add a
> git -C t stash
> ˋˋˋ
>
> ˋˋˋ
> + git init t
> Initialized empty Git repository in /private/tmp/t/t/.git/
> + git -C t commit --allow-empty -m 'initial commit'
> [master (root-commit) 858132e] initial commit
> + touch t/a
> + git -C t add --intent-to-add a
> + git -C t stash
> error: Entry 'a' not uptodate. Cannot merge.
> Cannot save the current worktree state
> ˋˋˋ

This is one of the well-known fundamental limitations of the design
of "git stash".

States in the index like "it is known that this path would be added
with some contents, but not quite added yet as the final contents
have not been decided (aka intent-to-add)" and "there are
conflicting wishes for the contents for this path and the final
decision has not bee made (aka unmerged)" cannot be left undecided
before getting written to a tree object (hence a commit object that
is used to represent a stash entry).

```
