Created
March 20, 2018 19:58
-
-
Save mads-hartmann/97b31f418f652a8239e2e6461aae05d3 to your computer and use it in GitHub Desktop.
🤖 Tiny script to check if I had any dirty repos or un-pushed branches before sending my MBP to repair.
This file contains hidden or 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 | |
set -euo pipefail | |
function is-git-repository { | |
[[ -d "$1/.git" ]] || (cd "$1" && git rev-parse --git-dir > /dev/null 2>&1) | |
} | |
function echo-is-dirty { | |
cd "$1" | |
if [[ ! -z $(git status -s) ]] | |
then echo "is dirty" | |
fi | |
} | |
function echo-unpushed-branches { | |
cd "$1" && git log --branches --not --remotes --no-walk --decorate --oneline | |
} | |
function main { | |
local path unpused | |
for kind in $(ls ~/dev); do | |
for project in $(ls ~/dev/${kind}); do | |
path="${HOME}/dev/${kind}/${project}" | |
echo "Checking project ${path}" | |
# Check if there are any unpushed branches | |
if is-git-repository "${path}"; then | |
echo-unpushed-branches "${path}" | |
echo-is-dirty "${path}" | |
fi | |
done | |
done | |
} | |
main $@ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment