git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* Possible BUG: git stash -m picks branch name from submodule
@ 2022-12-05 15:22 Flavio Stanchina
  0 siblings, 0 replies; only message 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] only message in thread

only message in thread, other threads:[~2022-12-05 15:25 UTC | newest]

Thread overview: (only message) (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

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).