From a2a33f1d06cd0f5ad5138bd2b6b302f4d3f3e38e Mon Sep 17 00:00:00 2001 From: sterni Date: Sun, 22 Dec 2024 14:05:07 +0100 Subject: [PATCH] feat(sterni/git-only-push): support force pushing This is occasionally necessary. --force-with-lease should also be supported in the future, unfortunately getopts(1) doesn't have --long option support. Change-Id: Ib054009f48585b1a52ed041a51bcaf7e32dca1b3 Reviewed-on: https://cl.tvl.fyi/c/depot/+/12904 Autosubmit: sterni Reviewed-by: sterni Tested-by: BuildkiteCI --- users/sterni/git-only-push/git-only-push.sh | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/users/sterni/git-only-push/git-only-push.sh b/users/sterni/git-only-push/git-only-push.sh index d425db271..304cbb11c 100755 --- a/users/sterni/git-only-push/git-only-push.sh +++ b/users/sterni/git-only-push/git-only-push.sh @@ -25,7 +25,7 @@ die() { usage() { printf '%s\n' \ - "git only-push [-n] [-x] [-b ] -r -t [--] ..." \ + "git only-push [-n] [-f] [-x] [-b ] -r -t [--] ..." \ >&2 } @@ -33,7 +33,7 @@ base=refs/remotes/origin/HEAD dry=false # TODO(sterni): non-interactive mode, e.g. clean up also on cherry-pick failure -while getopts "b:r:t:nxh" opt; do +while getopts "b:r:t:nxfh" opt; do case $opt in # TODO(sterni): it is probably too close to --branch? b) @@ -51,6 +51,10 @@ while getopts "b:r:t:nxh" opt; do x) cherry_pick_x=true ;; + f) + # TODO(sterni): support --force-with-lease + push_f=true + ;; h|?) usage # TODO(sterni): add man page @@ -60,6 +64,7 @@ while getopts "b:r:t:nxh" opt; do \t-t \tTarget ref to push to. \t-b \tOptional: Base revision to cherry-pick commits onto. Defaults to refs/remotes/origin/HEAD. \t-x\t\tUse `git cherry-pick -x` for creating cherry-picks. +\t-f\-\tForce push to remote ref. \t-n\t\tDry run. ' [ "$opt" = "h" ] && exit 0 || exit 100 @@ -124,5 +129,5 @@ done if $dry; then printf 'Would push resulting HEAD to %s on %s\n' "$to" "$remote" >&2 else - git push "$remote" "HEAD:$to" + git push ${push_f:+-f} "$remote" "HEAD:$to" fi