Skip to content

Instantly share code, notes, and snippets.

@mads-hartmann
Created March 20, 2018 19:58
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mads-hartmann/97b31f418f652a8239e2e6461aae05d3 to your computer and use it in GitHub Desktop.
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.
#!/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