views:

55

answers:

3

Somewhen (around the 1.6.x releases, I think) git became aware of changes inside submodules. That only serves to annoy me:

$ git status vendor | grep modified:
#       modified:   vendor/rails (modified content)
$ git diff vendor/
diff --git a/vendor/rails b/vendor/rails
--- a/vendor/rails
+++ b/vendor/rails
@@ -1 +1 @@
-Subproject commit 046c900df27994d454b7f906caa0e4226bb42b6f
+Subproject commit 046c900df27994d454b7f906caa0e4226bb42b6f-dirty

Please make it stop?

Edit:

Ok, so I have an answer. Now I have another question:

Can I put this in ~/.gitconfig? From my initial it appears that I cannot, and I didn't see anything promising by skimming the patch. (I guess I can still make an alias.)

+1  A: 

As you mention, the patch git submodule: ignore dirty submodules for summary and statu is in the making.

Also announced in the Git 1.7.2-rc2 release:

Git v1.7.2 Release Notes (draft)
================================

Updates since v1.7.1
--------------------

"git status" learned "--ignore-submodules" option.

So unless you compile a very latest version, you won't have this option yet in the current stable releases.


Regarding this as an option is not exactly the approach chosen for now:

After this series I am planning to add a config option 'ignore' to .gitmodules, which can be set for each submodule to either "all", "dirty", "untracked" or "none" (the default).

"git diff" and "git status" will use that config value for each submodule.
Using "--ignore-submodule" overrides this default (and the new parameter "none" will be added there to able to override the config settings).

And to avoid having to do "git submdule sync" every time that option changes, I would like to search for it in .git/config first.
If it is not found there, it will be taken from .gitmodules, if present.

So users can override the setting but if they don't, upstream can change it easily (e.g. when a submodules .gitignore has been updated so that "ignore=untracked" is no longer necessary anymore it can be removed).
Also switching branches will have an effect instantly if the 'ignore' entry in .gitmodules is different between branches.

VonC
Yeah thanks. That's what I was doing right now.
kch
I updated the question with a gitconfig bit. Just pinging in case you know the answer.
kch
@kch: I have updated the answer with the approach currently proposed for storing this kind of setting.
VonC
A: 

So git v1.7.2-rc2 has what I want:

$ git diff --ignore-submodules=dirty vendor
# no output
$ git status --ignore-submodules=dirty vendor
# On branch …
nothing to commit (working directory clean)

Building your own git howto:

# get git
git clone git://git.kernel.org/pub/scm/git/git.git git
cd git
git checkout v1.7.2-rc2

# make git. beware of setting prefix
make configure
./configure --prefix=/usr/local
make
sudo make install

# you REALLY don't want to `make doc`, use this instead
sudo make quick-install-man
sudo make quick-install-html
kch
A: 

So git 1.7.2 is out and includes the --ignore-submodules option for status.

From git help status:

--ignore-submodules[=<when>]
    Ignore changes to submodules when looking for changes.
    <when> can be either "untracked", "dirty" or "all", which
    is the default. When "untracked" is used submodules are
    not considered dirty when they only contain untracked
    content (but they are still scanned for modified content).
    Using "dirty" ignores all changes to the work tree of
    submodules, only changes to the commits stored in the
    superproject are shown (this was the behavior before
    1.7.0). Using "all" hides all changes to submodules (and
    suppresses the output of submodule summaries when the
    config option status.submodulesummary is set).

The value that I want is dirty.

git status --ignore-submodules=dirty

I use an alias because I'm lazy:

alias gst='git status --ignore-submodules=dirty'
kch