Created
July 7, 2011 09:04
-
-
Save ewoutvonk/1069142 to your computer and use it in GitHub Desktop.
Check dirtyness of git repository (working directory dirtyness, untracked files in working directory, unpushed commits, existing stashes, non-existing branches on remote origin)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
echo "$(basename $(pwd))..." ; git branch -a 2>/dev/null | cut -c 3- | perl -p -e 's#remotes/origin/##' | awk '{ print $1; }' | grep -v "remotes" | sort | uniq -c | awk '{ if($1=="2") { print $2; } ; }' | while read b ; do { [ ! -z "$(git cherry remotes/origin/$b $b 2>/dev/null)" ] && echo "$(basename $(pwd)): branch ${b} has unpushed commits" ; } ; done ; git branch -a 2>/dev/null | cut -c 3- | perl -p -e 's#remotes/origin/##' | awk '{ print $1; }' | grep -v "remotes" | sort | uniq -c | awk '{ if($1=="1") { print $2; } ; }' | while read b ; do { [ -z "$(git branch -a | cut -c 3- | awk -v branch="remotes/origin/${b}" '{ if($1==branch) { print $1; } ; }')" ] && echo "$(basename $(pwd)): branch ${b} does not exist on remote origin" ; } ; done ; [ ! -z "$(git status --porcelain -uno 2>/dev/null)" ] && echo "$(basename $(pwd)): working directory is dirty" ; [ ! -z "$(git status --porcelain -uall 2>/dev/null | perl -n -e 'm/^\?\?/ && print')" ] && echo "$(basename $(pwd)): working directory contains untracked files" ; [ ! -z "$(git stash list 2>/dev/null)" ] && echo "$(basename $(pwd)): there are existing stashes" ; git status 1>/dev/null 2>&1 || echo "$(basename $(pwd)): WARNING, not a git repository" ; [ -z "$(git remote -v 2>/dev/null | grep '^origin')" ] && echo "$(basename $(pwd)): WARNING: there's no remote called origin" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
echo "$(basename $(pwd))..." | |
git branch -a 2>/dev/null | | |
cut -c 3- | | |
perl -p -e 's#remotes/origin/##' | | |
awk '{ print $1; }' | | |
grep -v "remotes" | | |
sort | | |
uniq -c | | |
awk '{ if($1=="2") { print $2; } ; }' | | |
while read b ; do { | |
[ ! -z "$(git cherry remotes/origin/$b $b 2>/dev/null)" ] && | |
echo "$(basename $(pwd)): branch ${b} has unpushed commits" ; | |
} ; done | |
git branch -a 2>/dev/null | | |
cut -c 3- | | |
perl -p -e 's#remotes/origin/##' | | |
awk '{ print $1; }' | | |
grep -v "remotes" | | |
sort | | |
uniq -c | | |
awk '{ if($1=="1") { print $2; } ; }' | | |
while read b ; do { | |
[ -z "$(git branch -a | cut -c 3- | awk -v branch="remotes/origin/${b}" '{ if($1==branch) { print $1; } ; }')" ] && | |
echo "$(basename $(pwd)): branch ${b} does not exist on remote origin" ; | |
} ; done | |
[ ! -z "$(git status --porcelain -uno 2>/dev/null)" ] && | |
echo "$(basename $(pwd)): working directory is dirty" | |
[ ! -z "$(git status --porcelain -uall 2>/dev/null | perl -n -e 'm/^\?\?/ && print')" ] && | |
echo "$(basename $(pwd)): working directory contains untracked files" | |
[ ! -z "$(git stash list 2>/dev/null)" ] && | |
echo "$(basename $(pwd)): there are existing stashes" | |
git status 1>/dev/null 2>&1 || | |
echo "$(basename $(pwd)): WARNING: not a git repository" | |
[ -z "$(git remote -v 2>/dev/null | grep '^origin')" ] && | |
echo "$(basename $(pwd)): WARNING: there's no remote called origin" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment