git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Flavio Stanchina <flavio.stanchina@gmail.com>
To: git@vger.kernel.org
Subject: Possible BUG: git stash -m picks branch name from submodule
Date: Mon, 5 Dec 2022 16:22:05 +0100	[thread overview]
Message-ID: <cddbcbea-61c5-50c6-624f-5c7708b27f79@gmail.com> (raw)

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


                 reply	other threads:[~2022-12-05 15:25 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=cddbcbea-61c5-50c6-624f-5c7708b27f79@gmail.com \
    --to=flavio.stanchina@gmail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).