Skip to content

Instantly share code, notes, and snippets.

@rk295
Last active October 3, 2016 13:51
Show Gist options
  • Save rk295/72ca8b2caed696d78f89ca8a2db897ce to your computer and use it in GitHub Desktop.
Save rk295/72ca8b2caed696d78f89ca8a2db897ce to your computer and use it in GitHub Desktop.
This is a new command for [gg-core](https://github.com/fidian/gg-core), the tech behind [gg](https://github.com/fidian/gg). This adds the ability to switch all projects to master if possible.
#!/usr/bin/env bash
commandAdd master cmdMaster
cmdMasterHelp() {
cat <<EOF
master Switches all repos to be on the master branch
EOF
}
# Get a status of the project
cmdMaster() {
projectForEach cmdMasterEach
}
# Called for each project. Checks out the master branch.
#
# $1 - Project identifier.
#
# Always returns true. Can never fail.
cmdMasterEach() {
local path masterResult
path="$(getProjectConfig "$1" path)"
if [[ -z "$path" ]]; then
status "$1: No path set."
return 0
fi
if [[ ! -d "$path" ]]; then
status "$1: Not checked out."
return 0
fi
masterResult=$(cd "$path" ; git checkout master)
if echo "$masterResult" | grep -q "^nothing to commit, working directory clean$"; then
status "$1: clean"
else
status "$1: dirty"
echo "$masterResult"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment