Git -diff in a different directory

I am currently writing a small zsh function that checks all my git repos to see if they are dirty or not and then prints out the ones that need to be committed. So far, I've figured out that the fastest way to determine the git state of a clean / dirty repository is through 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:

  • Does anyone know of a faster and more efficient way to check for file changes / additions in a git repository
  • I want my zsh function to pass a file path (say ~/Code/git-repos/

    ) and check all repositories. Is there a way to get by without using cd in each directory and run those commands? Something like git-diff --quiet --git-dir="~/Code/git-repos/..."

    it would be fantastic.

Thanks!:)

+2


a source to share


1 answer


If it $DIR

contains the name of your directory, and the standard link (ie .git

dir $DIR/.git

), then git --git-dir $DIR/.git --work-tree $DIR status -s -uno

lists all files with pending changes. Checking for an empty list will give you what you want.



+3


a source







All Articles