always push what has been changed at destination

This commit is contained in:
Earl Warren 2023-12-23 21:09:43 +01:00
parent 18b334170a
commit 109016e50d
No known key found for this signature in database
GPG key ID: 0579CB2928A78A00

View file

@ -33,11 +33,15 @@ function default_branch() {
jq --raw-output .default_branch < $TMPDIR/$direction.json jq --raw-output .default_branch < $TMPDIR/$direction.json
} }
function updated_at() { function destination_updated_at() {
local direction=$1 local api
repo_curl ${options[${direction}_repo]} api_json ${options[${direction}_api]} > $TMPDIR/$direction.json if ${options[destination_is_fork]} ; then
jq --raw-output .updated_at < $TMPDIR/$direction.json repo_curl ${options[destination_repo]} api_json ${options[destination_fork_api]} > $TMPDIR/updated_at.json
else
repo_curl ${options[destination_repo]} api_json ${options[destination_api]} > $TMPDIR/updated_at.json
fi
jq --raw-output .updated_at < $TMPDIR/updated_at.json
} }
function exists_branch() { function exists_branch() {
@ -218,17 +222,25 @@ function sha_pushed() {
fi fi
} }
function destination_updated_at_changed() {
local before="$1"
local after="$(destination_updated_at)"
test "$before" != "$after"
}
function push() { function push() {
local direction=$1 remote=$2 branch=$3 local remote=$1 branch=$2
( (
cd $TMPDIR/$direction cd $TMPDIR/destination
git add . git add .
if git commit -m 'cascading-pr update'; then if git commit -m 'cascading-pr update'; then
local updated_at=$(updated_at $direction) local before=$(destination_updated_at)
sleep 1 # the resolution of the update time is one second
git push --force ${remote} prbranch:$branch git push --force ${remote} prbranch:$branch
git rev-parse HEAD > ../$direction.sha git rev-parse HEAD > ../destination.sha
retry test "$updated_at" != "$(updated_at $direction)" retry destination_updated_at_changed "$before"
local after=$(destination_updated_at)
log_info "pushed" log_info "pushed"
else else
log_info "nothing to push" log_info "nothing to push"
@ -310,7 +322,7 @@ function update() {
if ${options[destination_is_fork]} ; then if ${options[destination_is_fork]} ; then
remote_head=fork remote_head=fork
fi fi
push destination $remote_head ${options[destination_head]} push $remote_head ${options[destination_head]}
} }
function set_git_url() { function set_git_url() {