Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect and handle detached HEAD state #4

Merged
merged 7 commits into from Jul 19, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 12 additions & 7 deletions src/git-status.sh
Expand Up @@ -5,16 +5,21 @@ GREEN='\033[0;32m'
CYAN='\033[1;36m'
NC='\033[0m'

UPSTREAM=${1:-'@{u}'}
LOCAL=$(git rev-parse @)
REMOTE=$(git rev-parse "$UPSTREAM")
BASE=$(git merge-base @ "$UPSTREAM")
if ! git symbolic-ref --short HEAD 2>/dev/null; then
echo "${CYAN}?${NC} Deteached HEAD"
exit 1
fi

if [ $LOCAL = $REMOTE ]; then
UPSTREAM=${1:-'@{u}'};
LOCAL=$(git rev-parse @);
REMOTE=$(git rev-parse "$UPSTREAM");
BASE=$(git merge-base @ "$UPSTREAM");

if [ "${LOCAL}" = "${REMOTE}" ]; then
echo "${GREEN}✓${NC} Up to date"
elif [ $LOCAL = $BASE ]; then
elif [ "${LOCAL}" = "${BASE}" ]; then
echo "${RED}▼${NC} Pull Needed"
elif [ $REMOTE = $BASE ]; then
elif [ "${REMOTE}" = "${BASE}" ]; then
echo "${CYAN}▲${NC} Push Needed"
else
echo "${RED}✗${NC} Diverged"
Expand Down