git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Possible BUG: git stash -m picks branch name from submodule
@ 2022-12-05 15:22 Flavio Stanchina
  0 siblings, 0 replies; 2+ messages in thread
From: Flavio Stanchina @ 2022-12-05 15:22 UTC (permalink / raw)
  To: git

I have a repository with one submodule:
   $ cat .gitmodules
   [submodule "foo"]
     path = foo
     url = https://gitlab.xx.yy/zz/foo.git
     branch = xxx

After I clone the main repo and run "git submodule init" + "git 
submodule update", the submodule is in a detached state:
   $ (cd foo && git status)
   HEAD detached at cb52389b
   nothing to commit, working tree clean

I was expecting it to be on the branch spelled out in the configuration, 
but I guess this is working as designed: that's the correct commit, so 
nothing to worry about yet.

At this point, if I create a stash in the main repo with -m, the stash 
comment correctly says it was on master:
   $ git stash -m "test prestazioni filtri RFID"
   Saved working directory and index state On master:
   test prestazioni filtri RFID

   $ git stash list
   stash@{0}: On master: test prestazioni filtri RFID

Now I explicitly check out the submodule by branch name, in preparation 
for work in the submodule itself:
   $ (cd foo && git checkout xxx)
   Switched to branch 'xxx'
   Your branch is up to date with 'origin/xxx'.

   $ (cd foo && git log -1)
   commit cb52389b (HEAD -> xxx, origin/xxx)
   Author: Flavio Stanchina [...]

I create a stash in the main directory with exactly the same command as 
before:
   $ git stash -m "test prestazioni filtri RFID"
   Saved working directory and index state On xxx:
   test prestazioni filtri RFID

   $ git stash list
   stash@{0}: On xxx: test prestazioni filtri RFID

As you can see, the stash took the branch name from the submodule (there 
is no branch with that name in the main repo, and it's still on master 
anyway).

This doesn't happen if I just run "git stash" without -m:
   $ git stash
   Saved working directory and index state WIP on master:
   7bf81a83 [...]

   $ git stash list
   stash@{0}: WIP on master: 7bf81a83 [...]

Is this expected? I don't think so.

Am I not supposed to touch the submodule directory in any way? Even if 
that's the case, why would it make sense to pick the branch name from 
the submodule when stashing in the main directory?

Running on Debian 11 in a WSL instance:
   $ git --version
   git version 2.30.2

   $ dpkg -s git
   ...
   Version: 1:2.30.2-1
   ...


-- 
Ciao, Flavio


^ permalink raw reply	[flat|nested] 2+ messages in thread
* Re: Possible BUG: git stash -m picks branch name from submodule
@ 2025-04-30 14:05 Alex Arques
  0 siblings, 0 replies; 2+ messages in thread
From: Alex Arques @ 2025-04-30 14:05 UTC (permalink / raw)
  To: flavio.stanchina@gmail.com; +Cc: git@vger.kernel.org

I also encountered this today on “git version 2.49.0.windows.1” in a repository with two submodules, both which are set up to track “master”.

Whenever I do “git stash push” with a message on the main repository my stash message seems to be prepended with “On master: “.
This only works correctly if I omit the “-m” or “—message” part of “git stash push”.

git stash with no arguments outputs this:
Saved working directory and index state WIP on <current branch>

While git stash -m “[…]” outputs this:
Saved working directory and index state On master: […]

Which is not what I want because “git stash list” now gives me confusing output.
It seems like I have encountered the same bug? <current branch> on the main repository is NOT “master”.

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

end of thread, other threads:[~2025-04-30 14:05 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-12-05 15:22 Possible BUG: git stash -m picks branch name from submodule Flavio Stanchina
  -- strict thread matches above, loose matches on Subject: below --
2025-04-30 14:05 Alex Arques

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