src/grd: Add option for cherry-picking
Option '-c|--cherry-pick' will now cherry-pick into
the current branch if passed.
Change-Id: I85b1a2c4915e3da374e4b1201f2e977708fc7c4c
diff --git a/src/grd b/src/grd
index b1623ec..0ca5df7 100755
--- a/src/grd
+++ b/src/grd
@@ -69,6 +69,14 @@
except subprocess.CalledProcessError:
exit(1)
+def git_cherry_pick_fetch_head():
+ cmd = ["git", "cherry-pick", "FETCH_HEAD"];
+ print(f"+ {' '.join(cmd)}")
+
+ try:
+ return subprocess.run(cmd, check=True)
+ except subprocess.CalledProcessError:
+ exit(1)
def git_checkout_fetch_head(patch_id, rev):
cmd = ["git", "checkout", "-B", f"gerrit/{patch_id}_{rev}", "FETCH_HEAD"]
@@ -84,6 +92,9 @@
parser = argparse.ArgumentParser(description=desc)
parser.add_argument("patch_id", type=int,
help="gerrit review ID")
+parser.add_argument("-c", "--cherry-pick", action="store_true",
+ help="cherry-pick into current branch instead of "
+ "fetching into a branch")
parser.add_argument("-r", "--revision", type=int,
help="patchset revision, default is latest")
parser.add_argument("-v", "--verbose", action="store_true")
@@ -97,4 +108,7 @@
rev = get_highest_revision(details)
git_fetch(host, project, args.patch_id, rev)
-git_checkout_fetch_head(args.patch_id, rev)
+if args.cherry_pick:
+ git_cherry_pick_fetch_head()
+else:
+ git_checkout_fetch_head(args.patch_id, rev)