about summary refs log tree commit diff
diff options
context:
space:
mode:
authorsterni <sternenseemann@systemli.org>2024-12-22T13·03+0100
committerclbot <clbot@tvl.fyi>2024-12-22T13·30+0000
commit8459ad94fafc2a86e037d4ca4103516d7afc8930 (patch)
tree5933b184a4642f3e2e1227da5b8daf7cbefec6a2
parentb8342a821b4386ea571b56a8818e041b39699643 (diff)
feat(sterni/git-only-push): allow using git cherry-pick -x r/9016
I've noticed git only-push is quite useful for creating backports for
nixpkgs stable branches which we need git cherry-pick -x for.

Change-Id: Ie20248d3d0c5fee5cdbd3b3a078439a99f597c02
Reviewed-on: https://cl.tvl.fyi/c/depot/+/12903
Reviewed-by: sterni <sternenseemann@systemli.org>
Tested-by: BuildkiteCI
Autosubmit: sterni <sternenseemann@systemli.org>
-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 e9f9e2dfc079..d425db27191e 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] [-b <rev>] -r <remote> -t <refspec> [--] <commit>..." \
+    "git only-push [-n] [-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:nh" opt; do
+while getopts "b:r:t:nxh" opt; do
   case $opt in
     # TODO(sterni): it is probably too close to --branch?
     b)
@@ -48,13 +48,18 @@ while getopts "b:r:t:nh" opt; do
     n)
       dry=true
       ;;
+    x)
+      cherry_pick_x=true
+      ;;
     h|?)
       usage
       # TODO(sterni): add man page
+      # shellcheck disable=SC2016
       [ "$opt" = "h" ] && printf '
 \t-r <remote>\tRemote to push to.
 \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-n\t\tDry run.
 '
       [ "$opt" = "h" ] && exit 0 || exit 100
@@ -106,7 +111,7 @@ for rev in $revs; do
     printf 'Would cherry pick %s\n' "$rev" >&2
   else
     no_cherry_pick=false
-    git cherry-pick "$rev" || no_cherry_pick=true
+    git cherry-pick ${cherry_pick_x:+-x} "$rev" || no_cherry_pick=true
     if $no_cherry_pick; then
       tmp="$worktree"
       # Prevent cleanup from removing the worktree