commit: 86f67d71e02b84c5abc733a23cc4fb8bac1f3f48
parent 728484ee05477e6adef752715c8e8ddf2413219a
Author: Michael Forney <mforney@mforney.org>
Date: Tue, 9 Apr 2019 20:08:34 -0700
scripts/commit.sh: Only commit if tree changed
Diffstat:
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/scripts/commit.sh b/scripts/commit.sh
@@ -5,12 +5,19 @@ branch=$2
tag=$3
out=$4
-if git -C "$repo" show-ref -q --verify "refs/heads/$branch" ; then
- set -- -p "$branch"
+if commit=$(git -C "$repo" show-ref -s --verify "refs/heads/$branch" 2>/dev/null) ; then
+ oldtree=$(git -C "$repo" rev-parse --verify "$branch^{tree}")
+ newtree=$(git -C "$repo" rev-parse --verify "$tag^{tree}")
+ if [ "$oldtree" != "$newtree" ] ; then
+ set -- -p "$branch"
+ unset commit
+ fi
else
set --
fi
-commit=$(git -C "$repo" commit-tree -m "oasis built by $(id -un)" "$@" "$tag")
-git -C "$repo" update-ref "refs/heads/$branch" "$commit"
+if [ -z "${commit+set}" ] ; then
+ commit=$(git -C "$repo" commit-tree -m "oasis built by $(id -un)" "$@" "$tag")
+ git -C "$repo" update-ref "refs/heads/$branch" "$commit"
+fi
echo "$commit" >"$out.tmp" && mv "$out.tmp" "$out"