ABach
ABach

Reputation: 3738

git-diff in another directory

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! :)

Upvotes: 2

Views: 1602

Answers (1)

Oblomov
Oblomov

Reputation: 769

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.

Upvotes: 3

Related Questions