parent
20a088e96d
commit
ae9dd17ef3
1 changed files with 18 additions and 4 deletions
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue