add -u stages submodule changes when ignore=all is set

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux