git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Crockett, Eric" <ericcro@amazon.com>
To: "git@vger.kernel.org" <git@vger.kernel.org>
Subject: add -u stages submodule changes when ignore=all is set
Date: Fri, 29 May 2020 21:33:41 +0000	[thread overview]
Message-ID: <f60c88d8ec2e4efcbbf4f78fd8f87da6@EX13D20UWA002.ant.amazon.com> (raw)

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

                 reply	other threads:[~2020-05-29 21:33 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

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

  git send-email \
    --in-reply-to=f60c88d8ec2e4efcbbf4f78fd8f87da6@EX13D20UWA002.ant.amazon.com \
    --to=ericcro@amazon.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.
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).