Skip to content

Commit

Permalink
give input option to continue or not
Browse files Browse the repository at this point in the history
Summary:
to ask for input option:

1) If not running in master branch, ask for continue or not.
The default option is "n".

2) If local version is different with "origin/master",
to ask for doing 'git pull' or not. The default option
is "y".

Test Plan:
Test in my local mac when switch in different branch
and revision.

Reviewers: benkraft, csilvers

Reviewed By: benkraft, csilvers

Differential Revision: https://phabricator.khanacademy.org/D55648
  • Loading branch information
Kai Jing committed Jun 27, 2019
1 parent 3a18b55 commit e8c4074
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions git_sync.sh
Original file line number Diff line number Diff line change
@@ -1,25 +1,33 @@
#!/usr/bin/env bash

# Load shared setup functions.
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd -P )"
. "$SCRIPT_DIR/shared-functions.sh"

# Find the git repo, branch, etc in "khan-dotfiles"
REPO="$(basename `git rev-parse --show-toplevel`)"
BRANCH="$(git rev-parse --abbrev-ref HEAD 2>/dev/null)"
LOCAL_SHA=$(git rev-parse --verify HEAD)
REMOTE_SHA=$(git rev-parse --verify FETCH_HEAD)
REMOTE_SHA=$(git ls-remote . | grep refs/remotes/origin/HEAD | cut -f 1)

echo "Welcome to Khan-dotfiles!"
if [ -z "$BRANCH" ]; then
echo "Error: Could not locate a git branch in $REPO"
exit 1
fi

# Check if we're on the master branch.
if [ "$BRANCH" != "master" ]; then
echo "Your directory is running branch \"$BRANCH\""
echo "You need to run in master branch at \"$REPO\""
exit 1
fi
echo "Running branch \"$BRANCH\", not master."
[ ! "$(get_yn_input "Would you like to continue?" "n")" != "y" ]
exit $?

fi
if [ $LOCAL_SHA != $REMOTE_SHA ]; then
echo "your local repo \"$REPO\" is different with 'origin/master'"
echo "please 'git pull' and re-run 'make' "
exit 1
echo "your local repo \"$REPO\" is different from 'origin/master'"
if [ "$(get_yn_input "Would you like to run 'git pull'?" "y")" = "y" ]; then
git pull
else
exit 0
fi
fi

0 comments on commit e8c4074

Please sign in to comment.