From 8459ad94fafc2a86e037d4ca4103516d7afc8930 Mon Sep 17 00:00:00 2001 From: sterni Date: Sun, 22 Dec 2024 14:03:23 +0100 Subject: [PATCH] feat(sterni/git-only-push): allow using git cherry-pick -x 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 Tested-by: BuildkiteCI Autosubmit: sterni --- 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 e9f9e2dfc..d425db271 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 ] -r -t [--] ..." \ + "git only-push [-n] [-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: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 \tRemote to push to. \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-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