git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* add -u stages submodule changes when ignore=all is set
@ 2020-05-29 21:33 Crockett, Eric
  0 siblings, 0 replies; only message in thread
From: Crockett, Eric @ 2020-05-29 21:33 UTC (permalink / raw)
  To: git@vger.kernel.org

My expectation is that `git add -u` will stage precisely the changes listed in `git status` under "Changes not staged for commit". However, this isn't the case, and it's confusing. In particular, if I set `ignore=all` in .gitmodules for a submodule and then make changes to that submodule, `git status` does not show the changes (which is what I expect), but `git add -u` still stages the changes to the submodule (not what I expect)! This behavior occurs with git 2.26.2 on Ubuntu 18.04.

This script demonstrates the problem:

#!/bin/bash -ex

echo "Check out a random repository"
git clone https://github.com/crockeea/cryptonite.git
cd cryptonite

echo "Add a random submodule"
git submodule add https://github.com/crockeea/wai.git

echo "Track an older commit in the submodule"
cd wai
git checkout HEAD^
cd ..
git add -A
git commit -m "Added submodule one commit behind its tip-of-master"

echo "What happens if I check out a newer commit in the submodule?"
cd wai
git checkout master
cd ..
git status
echo "git status shows that the submodule is dirty"

echo "We can fix that by adding `ignore=all` to .gitmodules"
echo -e '\tignore = all' >> .gitmodules

git status
echo "Now the dirty submodule is not shown"

echo "This looks good; let's stage the changes to .gitmodules"
git add -u

echo "And verify what was staged..."
git status
echo "The dirty submodule was staged! This is not what I expect."
echo "I expect that `git add -u` will only stage the changes to .gitmodules"

cd ..
rm -rf cryptonite


Regards,
Eric Crockett

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-05-29 21:33 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-29 21:33 add -u stages submodule changes when ignore=all is set Crockett, Eric

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