Comments on 2019-05-27 Programmatically checking for uncommitted changes

Last edit

Summary: Wow, thanks for all these comments! As for the if-then-else stuff, I obviously have other things inside - {{{exit 0}}} and {{{exit 1}}} were just . . .

Added:

> ----
> Wow, thanks for all these comments!
> As for the if-then-else stuff, I obviously have other things inside - {{{exit 0}}} and {{{exit 1}}} were just examples. I didn't know about {{{--untracked-files=no}}}, though I guess I knew about {{{-q}}}.
> As for {{{mr}}}, I will have to look into it -- thanks!
> Finally, I will also study the {{{git-diff}}} manual and {{{magit-list-repositories}}}.
> Thanks again!
> -- Marcin Borkowski 2019-06-03 18:49 UTC


This does rather more than it needs. A form of `if [[...?]] ; then exit 0 ; else exit 1 ; fi` can be replaced by `[[...?]]` as shell scripts exit with the return code of the last command they ran.

The grep is not needed, as `git status --untracked-files=no --porcelain` will filter out untracked files.

Finally `git status` has an exit code already. It happens to be inverted from the one you want, but iy you can tolerate that then adding a `-q` will give you a command that returns 1 if everything is clean and 0 if there is anything dirst or an error occurs.

– Anonymous 2019-05-27 18:47 UTC


A remark: I am a big fan of Emacs & Magit, however for these kind of problems (checking for uncommitted changes etc.. .multiple repos) I use this command line tool: mr (aka “my repos”) which I find really useful:

https://myrepos.branchable.com/
https://pixorblog.wordpress.com/2019/02/05/managing-a-collection-of-git-repositories/

– Anonymous 2019-05-28 09:23 UTC


You can also use `git diff` or one of its variants to for the same purpose:

git diff --exit-code --name-status HEAD

With `git-diff`, you can customize the output to any granularity you want.

Remember that magit already provides a command for checking the statuses of multiple reposiories: `magit-list-repositories`, though I’m not a big fan of it, because it is slow.

– Akira Komamura 2019-05-29 12:58 UTC


Wow, thanks for all these comments!

As for the if-then-else stuff, I obviously have other things inside - exit 0 and exit 1 were just examples. I didn’t know about --untracked-files=no, though I guess I knew about -q.

As for mr, I will have to look into it – thanks!

Finally, I will also study the git-diff manual and magit-list-repositories.

Thanks again!

– Marcin Borkowski 2019-06-03 18:49 UTC