tags:

views:

54

answers:

1

I'm currently writing a little zsh function that checks all of my git repositories to see if they're dirty or not and then prints out the ones that need a commit. Thus far, I've figured out that the quickest way to figure out a git repository's clean/dirty status is via git-diff and git-ls-files:

if ! git diff --quiet || git ls-files --others --exclude-standard; then
  state=":dirty"
fi

I have two questions for you folks:

  1. Does anyone know of a quicker, more efficient way to check for file changes/additions in a git repo?
  2. I want my zsh function to be handed a file path (say ~/Code/git-repos/) and check all of the repositories in it. Is there a way to do without having to cd into each directory and run those commands? Something like git-diff --quiet --git-dir="~/Code/git-repos/..." would be fantastic.

Thanks! :)

+2  A: 

If $DIR holds your directory name and it's a standard layout (i.e. the .git dir is $DIR/.git), then git --git-dir $DIR/.git --work-tree $DIR status -s -uno will list all the files that have uncommitted changes. Checking if the list is empty should give you what you want.

Oblomov
Running that command gives "fatal: Invalid untracked files mode '=none'." The man page specifies 'no' as a valid option for -u, but that gives a similar error.
ABach
You're right, sorry, the syntax was slightly off. Use -uno instead of -u=none
Oblomov
(I fixed the post accordingly)
Oblomov
A combination of this and @VonC's link above (in particular, the --porcelain flag for git status) is what did the trick.
ABach