-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathcheck_status_and_pull.sh
executable file
·54 lines (43 loc) · 1.17 KB
/
check_status_and_pull.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#! /usr/bin/env bash
# There are lots of places where we need to check stuff like:
# 1) Does repo X exist?
# 2) Does it have master checked out?
# 3) It is clean?
# 4) Is it up to date?
# This script takes care of all that.
set -e -u -o pipefail
repo="${1:-}"
if [ -z "$repo" ] ; then
echo "check_status_and_pull.sh needs a repo argument."
exit 1
fi
if [ ! -d "$repo" ] ; then
echo "Repo directory '$repo' does not exist."
exit 1
fi
cd "$repo"
if [ ! -d ".git" ] ; then
# This intentionally doesn't support bare repos. Some callers are going to
# want to mess with the working copy.
echo "Directory '$repo' is not a git repo."
exit 1
fi
# fetch upstream
git fetch
current_branch="$(git rev-parse --abbrev-ref HEAD)"
if [ "$current_branch" != "master" ] ; then
echo "Repo '$repo' doesn't have master checked out."
exit 1
fi
current_status="$(git status --porcelain)"
if [ -n "$current_status" ] ; then
echo "Repo '$repo' isn't clean."
exit 1
fi
unpushed_commits="$(git log origin/master..master)"
if [ -n "$unpushed_commits" ] ; then
echo "Repo '$repo' has unpushed commits."
exit 1
fi
echo "Repo '$repo' looks good. Pulling..."
git pull --ff-only