parent
20a088e96d
commit
ae9dd17ef3
1 changed files with 18 additions and 4 deletions
|
@ -57,6 +57,16 @@ error() {
|
||||||
errors[${#errors[*]}]="$1"
|
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
|
for branchspec in "${branches[@]}"; do
|
||||||
set $branchspec
|
set $branchspec
|
||||||
leader_sha="$1"
|
leader_sha="$1"
|
||||||
|
@ -66,18 +76,22 @@ for branchspec in "${branches[@]}"; do
|
||||||
echo
|
echo
|
||||||
echo "Updating $remote/$branch"
|
echo "Updating $remote/$branch"
|
||||||
|
|
||||||
# Prepare state to push
|
|
||||||
follower_ref="refs/remotes/$remote/$branch"
|
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"
|
echo "Branch doesn't exist yet at remote, creating"
|
||||||
git reset --hard "$leader_sha" --
|
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
|
else
|
||||||
echo "Branch existed at remote, updating"
|
echo "Branch existed at remote, updating"
|
||||||
git reset --hard "$follower_ref" --
|
git reset --hard "$follower_ref" --
|
||||||
git merge --ff-only "$leader_sha" || { error "$remote $branch: FF not possible"; continue; }
|
git merge --ff-only "$leader_sha" || { error "$remote $branch: FF not possible"; continue; }
|
||||||
fi
|
|
||||||
|
|
||||||
git push "$remote" "+HEAD:$branch" || { error "$remote $branch: failed to push"; continue; }
|
git push "$remote" "+HEAD:$branch" || { error "$remote $branch: failed to push"; continue; }
|
||||||
|
fi
|
||||||
|
|
||||||
done
|
done
|
||||||
done
|
done
|
||||||
|
|
Loading…
Reference in a new issue