about summary refs log tree commit diff
diff options
context:
space:
mode:
authorsterni <sternenseemann@systemli.org>2024-12-22T13·05+0100
committerclbot <clbot@tvl.fyi>2024-12-22T13·36+0000
commita2a33f1d06cd0f5ad5138bd2b6b302f4d3f3e38e (patch)
tree314f228c49fca5adca5678410e3c2e803f7a136b
parent8459ad94fafc2a86e037d4ca4103516d7afc8930 (diff)
feat(sterni/git-only-push): support force pushing r/9017
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 <sternenseemann@systemli.org>
Reviewed-by: sterni <sternenseemann@systemli.org>
Tested-by: BuildkiteCI
-rwxr-xr-xusers/sterni/git-only-push/git-only-push.sh11
1 files 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 d425db27191e..304cbb11c2ea 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 <rev>] -r <remote> -t <refspec> [--] <commit>..." \
+    "git only-push [-n] [-f] [-x] [-b <rev>] -r <remote> -t <refspec> [--] <commit>..." \
     >&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 <refspec>\tTarget ref to push to.
 \t-b <rev>\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