Skip to content
This repository has been archived by the owner on Feb 15, 2022. It is now read-only.

Commit

Permalink
Updating git_commit_if_changed in build.sh to accept a variable for t…
Browse files Browse the repository at this point in the history
…racking changes (#1206)
  • Loading branch information
mtarng authored Mar 19, 2020
1 parent 99572da commit ab89240
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions gitops/azure-devops/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,8 @@ function git_commit() {

# Checks for changes and only commits if there are changes staged. Optionally can be configured to fail if called to commit and no changes are staged.
# First arg - commit message
# Second arg - should fail if there is nothing to commit, any non 0 value.
# Second arg - "should error if there is nothing to commit" flag. Set to 0 if this behavior should be skipped and it will not error when there are no changes.
# Third arg - variable to check if changes were commited or not. Will be set to 1 if changes were made, 0 if not.
function git_commit_if_changes() {

echo "GIT STATUS"
Expand All @@ -254,13 +255,21 @@ function git_commit_if_changes() {
echo "GIT ADD"
git add -A

if [[ $(git status --porcelain) ]] || [[ $2 ]]; then
commitSuccess=0
if [[ $(git status --porcelain) ]] || [ -z "$2" ]; then
echo "GIT COMMIT"
git commit -m "Updated k8s manifest files post commit: $1"
retVal=$? && [ $retVal -ne 0 ] && exit $retVal
git commit -m "$1"
retVal=$?
if [[ "$retVal" != "0" ]]; then
echo "ERROR COMMITING CHANGES -- MAYBE: NO CHANGES STAGED"
exit $retVal
fi
commitSuccess=1
else
echo "NOTHING TO COMMIT"
fi
echo "commitSuccess=$commitSuccess"
printf -v $3 "$commitSuccess"
}

# Perform a Git push
Expand Down

0 comments on commit ab89240

Please sign in to comment.