I’m writing a script to run things like git status in each of the subdirectories of the current directory, so I can quickly get information about several git repos. However, I want to prevent any commands that modify the repos. I wouldn’t want to commit ten repos at once. I can’t just use a whitelist of git subcommands, because I might want to run git branch -a to see the branches in each repo, but not git branch new-branch-name to create a new branch in each repo.
So is there a way to run git so that it will abort instead of making anymodifications to the repo, but work fine when running read-only commands?
Edit: What I want to do is make a git-subdirs command that works like this: When I type git subdirs COMMAND ARGS, I want to do something like for dir in */; do cd $dir && git COMMAND ARGS && cd ..; done (only with additional error checking). Except that if git COMMAND ARGS would modify the repo in any way, I don’t want to do it, because it’s exceedingly unlikely that I would want to make the same change to many different repos.
I implemented this using unionfs-fuse. This is completely non-portable, but it works for me on Ubuntu. Try it out with
git subdirs statusin the directory that contains all your git repos.You can get it from Github: https://github.com/DarwinAwardWinner/git-custom-commands