-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
3 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# helper method for providing error messages for a command | ||
run_or_fail() { | ||
local explanation=$1 | ||
shift 1 | ||
"$@" | ||
if [ $? != 0 ]; then | ||
echo $explanation 1>&2 | ||
exit 1 | ||
fi | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/bin/bash | ||
REPO=$1 | ||
COMMIT=$2 | ||
|
||
source ./scripts/run_or_fail.sh | ||
|
||
run_or_fail "Repository folder not found" pushd "$REPO" 1> /dev/null | ||
run_or_fail "Could not clean repository" git clean -d -f -x | ||
run_or_fail "Could not call git pull" git pull | ||
run_or_fail "Could not update to given commit hash" git reset --hard "$COMMIT" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#!/bin/bash | ||
|
||
source ./scripts/run_or_fail.sh | ||
|
||
# delete previous id | ||
rm -f files/.commit_id | ||
|
||
# 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 id | ||
COMMIT_ID=`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 id | ||
NEW_COMMIT_ID=`echo $COMMIT | awk '{ print $2 }'` | ||
|
||
# if the id changed, then write it to a file | ||
if [ $NEW_COMMIT_ID != $COMMIT_ID ]; then | ||
popd 1> /dev/null | ||
echo $NEW_COMMIT_ID > .commit_id | ||
fi |