git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Possible BUG: git stash -m picks branch name from submodule

From
FSFlavio Stanchina <flavio.stanchina@gmail.com>
Date
Dec 5, 2022, 15:22 UTC
Message-ID
<cddbcbea-61c5-50c6-624f-5c7708b27f79@gmail.com>
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
Message 1 of 1 in “Possible BUG: git stash -m picks branch name from submodule”
  1. Flavio StanchinaDec 5, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.