Commit ae9dd17e authored by midgard's avatar midgard

Detect when no push is necessary

Fixes #1
parent 20a088e9
......@@ -57,6 +57,16 @@ error() {
errors[${#errors[*]}]="$1"
}
ref_exists() {
git show-ref --verify --quiet "$1"
}
is_ref_at_sha() {
sha1="$(git show-ref --verify --hash "$1")"
sha2="$2"
[[ $sha1 == $sha2 ]]
}
for branchspec in "${branches[@]}"; do
set $branchspec
leader_sha="$1"
......@@ -66,19 +76,23 @@ for branchspec in "${branches[@]}"; do
echo
echo "Updating $remote/$branch"
# Prepare state to push
follower_ref="refs/remotes/$remote/$branch"
if ! git show-ref --verify --quiet "$follower_ref"; then
if ! ref_exists "$follower_ref"; then
echo "Branch doesn't exist yet at remote, creating"
git reset --hard "$leader_sha" --
git push "$remote" "+HEAD:$branch" || { error "$remote $branch: failed to push"; continue; }
elif is_ref_at_sha "$follower_ref" "$leader_sha"; then
echo "Branch up to date"
else
echo "Branch existed at remote, updating"
git reset --hard "$follower_ref" --
git merge --ff-only "$leader_sha" || { error "$remote $branch: FF not possible"; continue; }
git push "$remote" "+HEAD:$branch" || { error "$remote $branch: failed to push"; continue; }
fi
git push "$remote" "+HEAD:$branch" || { error "$remote $branch: failed to push"; continue; }
done
done
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment