-
-
Save dbu/2843660 to your computer and use it in GitHub Desktop.
#!/usr/bin/php | |
<?php | |
$repos = array(); | |
exec('find -type d -name .git | sed -e "s/\.git//"', $repos); | |
foreach ($repos as $repo) { | |
$status = shell_exec("cd $repo && git status"); | |
if (false == strpos($status, 'nothing to commit (working directory clean)')) { | |
echo "$repo\n" . str_repeat('-', strlen($repo)) . "\n$status\n\n"; | |
} | |
} |
@hoijui Try creating a .git
folder inside bla.github
(and remove the top .git
folder to avoid an error because it is not a valid git
folder), and then run your script. I get this:
fatal: cannot change to './blahub/': No such file or directory
The problem is not with the find . -name '.git'
line but with the repo=${repo//\.git/}
line. Using this instead
repo=${repo%".git"}
seems to do the trick.
ahh very good, thank you @Gabriel-p!
//
replaces anywhere, %
replaces only a match on the end of the string, so %
is to be used here.
fixed version of the script:
#!/usr/bin/env bash
# Recursive `git status` (including sub-modules)
set -e
status_ops="$*"
find . -name '.git' \
| while read -r repo
do
repo=${repo%".git"}
(git -C "$repo" status -s \
| grep -q -v "^\$" \
&& echo -e "\n\033[1m${repo}\033[m" \
&& git -C "$repo" status $status_ops) \
|| true
done
... and as one-liner:
find . -name '.git' | while read -r repo ; do repo=${repo%".git"}; (git -C "$repo" status -s | grep -q -v "^\$" && echo -e "\n\033[1m${repo}\033[m" && git -C "$repo" status -s) || true; done
For Windows users... try this in the root folder above the folders to search:
for /f "tokens=*" %a in ('dir .git /adh /b /s') do (echo off & cd "%~pa" & cd & git status -s)
(The echo off
helps the output look less cluttered but may wreck your prompt. If so, exit the window when done.)
@glittle , awesome,
If you want to check all git folders in "C:\some-folder" run the following (1 level, runs faster)
for /f "tokens=*" %a in ('dir /ad /b') do (echo off & cd "c:\\some-folder\\%~a" & cd & git status -s)
You don't need to search everything. Do:
find . -maxdepth 2 -name .git -type d -exec sh -c "cd {}/..;git status" \;
find . -name '.git' | while read repo; do echo -e "\n$(dirname $repo)"; git --git-dir=$repo --work-tree=$(dirname $repo) status -s -b; done
ahh very good, thank you @Gabriel-p!
//
replaces anywhere,%
replaces only a match on the end of the string, so%
is to be used here.fixed version of the script:
#!/usr/bin/env bash # Recursive `git status` (including sub-modules) set -e status_ops="$*" find . -name '.git' \ | while read -r repo do repo=${repo%".git"} (git -C "$repo" status -s \ | grep -q -v "^\$" \ && echo -e "\n\033[1m${repo}\033[m" \ && git -C "$repo" status $status_ops) \ || true done... and as one-liner:
find . -name '.git' | while read -r repo ; do repo=${repo%".git"}; (git -C "$repo" status -s | grep -q -v "^\$" && echo -e "\n\033[1m${repo}\033[m" && git -C "$repo" status -s) || true; done
I discovered from here that if you want to run that script as a git command without making an alias, you have to:
- Name your script: "git-command"
- Make your script executable
- Move your script to a directory that's in your PATH
E.g.:
If your PATH contains ~/.local/bin/ and you named your script "git-str" then:
chmod +x git-str && mv git-str ~/.local/bin/
Now you can run: git str.
To any Linux novice, beware of what script you make executable, as it may be dangerous for your system.
(The
echo off
helps the output look less cluttered but may wreck your prompt. If so, exit the window when done.)
after the command is done, typing echo on
will bring back the prompt.
This one (1) produces a slim output, and (2) starts printing the results instantly (you don't have to wait it to finish to see the final output):
find . -maxdepth 2 -name .git -type d -exec sh -c "cd {}/..; pwd; git status -s" \;
@Gabriel-p strange.. it does not happen here. :-/
I tested it like this:
Which spits out only this:
which I think.. is what should happen, according to the man page of
find
;-name
should match only on the complete file name.Is it possible that you are using some obscure version of
find
? maybe OSX?though even there it woudl be strange to diverge like this... I don't know!