git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Why can't I stash submodule changes?
@ 2015-04-06  2:15 Shane da Silva
  2015-04-06 15:14 ` Phillip Susi
  2015-04-06 17:58 ` Jens Lehmann
  0 siblings, 2 replies; 4+ messages in thread
From: Shane da Silva @ 2015-04-06  2:15 UTC (permalink / raw)
  To: git

I’m having trouble understanding why I cannot stash changes to a submodule.

When adding a submodule to a repository (`git submodule add
./sub-repo`), I can then run `git stash` and `git stash pop` with
expected results—the submodule disappears and reappears in the working
tree.

However, when I try stashing an update to a submodule, `git stash`
reports “No local changes to save”. The following shell script
illustrates this behavior:


# Create repo
mkdir test-repo
cd test-repo
git init
git commit --allow-empty -m "Initial commit"

# Create submodule
mkdir sub-repo
cd sub-repo
git init
git commit --allow-empty -m "Initial commit"
cd -

# Add submodule
git submodule add ./sub-repo
git commit -m "Add submodule"

# Modify submodule
cd sub-repo
touch foo
git add foo
git commit -m "Submodule changed"
cd -

# Stash submodule change
git stash # <---------------------------Displays "No local changes to save”


I’m trying to wrap my head around why this is the current behavior, as
I suspect this is intentional but it seems unexpected. If anyone can
shed any light on this, I would really appreciate it!

Thanks,

Shane

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Why can't I stash submodule changes?
  2015-04-06  2:15 Why can't I stash submodule changes? Shane da Silva
@ 2015-04-06 15:14 ` Phillip Susi
  2015-04-06 17:58 ` Jens Lehmann
  1 sibling, 0 replies; 4+ messages in thread
From: Phillip Susi @ 2015-04-06 15:14 UTC (permalink / raw)
  To: Shane da Silva, git

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 4/5/2015 10:15 PM, Shane da Silva wrote:
> I’m trying to wrap my head around why this is the current behavior,
> as I suspect this is intentional but it seems unexpected. If anyone
> can shed any light on this, I would really appreciate it!

Why would you expect anything else?  You have no local changes ( since
you committed them already ).  In other words, git status shows no
uncommitted changes, so there is nothing to stash.


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.17 (MingW32)

iQEcBAEBAgAGBQJVIqLsAAoJENRVrw2cjl5RFGsIAIC38/iZTQsYWfeS8mOt3DVY
jrRCrbfHcjQyKWsEk2seupEV1K1OO0lPhocRE4+3T+vAz3n9Wdc+ATuXNv41vmkY
r2R3VaTXimLw6NfaSxMfqEb4xL/9M0UhUS7SdEALVEApS4AySxYKWKL+RoqF0LWD
JgP6DHCzOLBy8cttaQppZdfRHa34FUmeH1k7m6r/14tarwcc+a3glVqW7i3gue7z
s3zhEkd+dqgab79TNj1gh86UE016UmG7yjbBTWKnNrYdTCW5IBCDqsp0We2PH1Jy
2QPckedCisroZjq0I4uAbuUCm94obiEJKclbY+Wl4sVdYb9rralBOJnPkKwRsiw=
=4ekO
-----END PGP SIGNATURE-----

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Why can't I stash submodule changes?
  2015-04-06  2:15 Why can't I stash submodule changes? Shane da Silva
  2015-04-06 15:14 ` Phillip Susi
@ 2015-04-06 17:58 ` Jens Lehmann
  2015-04-07  5:19   ` Shane da Silva
  1 sibling, 1 reply; 4+ messages in thread
From: Jens Lehmann @ 2015-04-06 17:58 UTC (permalink / raw)
  To: Shane da Silva, git

Am 06.04.2015 um 04:15 schrieb Shane da Silva:
> I’m having trouble understanding why I cannot stash changes to a submodule.
>
> When adding a submodule to a repository (`git submodule add
> ./sub-repo`), I can then run `git stash` and `git stash pop` with
> expected results—the submodule disappears and reappears in the working
> tree.

Just to be sure: Only the index of the superproject and the .gitmodules
file are updated by stash to either contain the submodule or not. But
the subdirectory "sub-repo" stays unchanged and won't be removed or
reappear, right?

> However, when I try stashing an update to a submodule, `git stash`
> reports “No local changes to save”. The following shell script
> illustrates this behavior:
>
>
> # Create repo
> mkdir test-repo
> cd test-repo
> git init
> git commit --allow-empty -m "Initial commit"
>
> # Create submodule
> mkdir sub-repo
> cd sub-repo
> git init
> git commit --allow-empty -m "Initial commit"
> cd -
>
> # Add submodule
> git submodule add ./sub-repo
> git commit -m "Add submodule"
>
> # Modify submodule
> cd sub-repo
> touch foo
> git add foo
> git commit -m "Submodule changed"
> cd -
>
> # Stash submodule change
> git stash # <---------------------------Displays "No local changes to save”

Thanks for providing a recipe to reproduce this!

> I’m trying to wrap my head around why this is the current behavior, as
> I suspect this is intentional but it seems unexpected. If anyone can
> shed any light on this, I would really appreciate it!

The current behavior of git is that submodule contents aren't updated
when the superproject changes. Running "git submodule update" later
will then update their content to most submodule changes (but e.g. it
won't remove a deleted submodule from the work tree). So yes, this is
expected until recursive submodule update materializes (and even then
I'm not sure how to handle untracked but not ignored files inside a
submodule when stashing will result in the submodule directory to be
removed).

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Why can't I stash submodule changes?
  2015-04-06 17:58 ` Jens Lehmann
@ 2015-04-07  5:19   ` Shane da Silva
  0 siblings, 0 replies; 4+ messages in thread
From: Shane da Silva @ 2015-04-07  5:19 UTC (permalink / raw)
  To: Jens Lehmann; +Cc: git

Thanks for your responses, all.

Jens: yes, only the index is updated by the stash. The subdirectory
remains and won't be removed (you will actually receive a warning
about `git` not being able to remove it).

I think the core of my misunderstanding is I was used to the idea that
when `git status` showed modifications to tracked files, `git stash`
would make those modifications disappear. Submodules are fundamentally
different, and it makes sense to me now why it wouldn't necessarily be
a good idea for `git stash` to be a mutating operation on submodules.

I ran into this behavior while debugging an issue with a git-hook
manager I maintain, called Overcommit
(https://github.com/brigade/overcommit). It was discovered that if you
only add submodule changes to the index and then run `git stash save
--keep-index`, an exit status of zero is returned even though no stash
was created. I had assumed that if the return code was zero, a stash
commit was created, but it makes sense why this is not the case.

Thanks again for your time in helping clarify this behavior.

On Mon, Apr 6, 2015 at 10:58 AM, Jens Lehmann <Jens.Lehmann@web.de> wrote:
> Am 06.04.2015 um 04:15 schrieb Shane da Silva:
>>
>> I’m having trouble understanding why I cannot stash changes to a
>> submodule.
>>
>> When adding a submodule to a repository (`git submodule add
>> ./sub-repo`), I can then run `git stash` and `git stash pop` with
>> expected results—the submodule disappears and reappears in the working
>> tree.
>
>
> Just to be sure: Only the index of the superproject and the .gitmodules
> file are updated by stash to either contain the submodule or not. But
> the subdirectory "sub-repo" stays unchanged and won't be removed or
> reappear, right?
>
>
>> However, when I try stashing an update to a submodule, `git stash`
>> reports “No local changes to save”. The following shell script
>> illustrates this behavior:
>>
>>
>> # Create repo
>> mkdir test-repo
>> cd test-repo
>> git init
>> git commit --allow-empty -m "Initial commit"
>>
>> # Create submodule
>> mkdir sub-repo
>> cd sub-repo
>> git init
>> git commit --allow-empty -m "Initial commit"
>> cd -
>>
>> # Add submodule
>> git submodule add ./sub-repo
>> git commit -m "Add submodule"
>>
>> # Modify submodule
>> cd sub-repo
>> touch foo
>> git add foo
>> git commit -m "Submodule changed"
>> cd -
>>
>> # Stash submodule change
>> git stash # <---------------------------Displays "No local changes to
>> save”
>
>
> Thanks for providing a recipe to reproduce this!
>
>> I’m trying to wrap my head around why this is the current behavior, as
>> I suspect this is intentional but it seems unexpected. If anyone can
>> shed any light on this, I would really appreciate it!
>
>
> The current behavior of git is that submodule contents aren't updated
> when the superproject changes. Running "git submodule update" later
> will then update their content to most submodule changes (but e.g. it
> won't remove a deleted submodule from the work tree). So yes, this is
> expected until recursive submodule update materializes (and even then
> I'm not sure how to handle untracked but not ignored files inside a
> submodule when stashing will result in the submodule directory to be
> removed).

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-04-07  5:19 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-06  2:15 Why can't I stash submodule changes? Shane da Silva
2015-04-06 15:14 ` Phillip Susi
2015-04-06 17:58 ` Jens Lehmann
2015-04-07  5:19   ` Shane da Silva

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).