-
Notifications
You must be signed in to change notification settings - Fork 0
/
update_repo.sh
37 lines (30 loc) · 933 Bytes
/
update_repo.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
#!/bin/bash
source run_or_fail.sh
# delete previous hash
rm -f .commit_hash
# go to repo and update it to given commit
run_or_fail "Repository folder not found!" pushd $1 1> /dev/null
run_or_fail "Could not reset git" git reset --hard HEAD
# get the most recent commit
COMMIT=$(run_or_fail "Could not call 'git log' on repository" git log -n1)
if [ $? != 0 ]; then
echo "Could not call 'git log' on repository"
exit 1
fi
# get its hash
HASH=`echo $COMMIT | awk '{ print $2 }'`
# update the repo
run_or_fail "Could not pull from repository" git pull
# get the most recent commit
COMMIT=$(run_or_fail "Could not call 'git log' on repository" git log -n1)
if [ $? != 0 ]; then
echo "Could not call 'git log' on repository"
exit 1
fi
# get its hash
NEWHASH=`echo $COMMIT | awk '{ print $2 }'`
# if the hash changed, then write it to a file
if [ $NEWHASH != $HASH ]; then
popd 1> /dev/null
echo $NEWHASH > .commit_id
fi