Skip to content

Commit

Permalink
Merge pull request twosigma#873 from cstaykov/cherry-pick
Browse files Browse the repository at this point in the history
Add no-commit option to cherry-pick
  • Loading branch information
tsiq-shu authored Dec 16, 2022
2 parents de11cfd + 2839613 commit b1e1908
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion node/lib/cmd/cherry_pick.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, Two Sigma Open Source
* Copyright (c) 2022, Two Sigma Open Source
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -68,6 +68,12 @@ exports.configureParser = function (parser) {
constant: true,
help: "continue an in-progress cherry-pick",
});
parser.addArgument(["-n", "--no-commit"], {
action: "storeConst",
constant: true,
help: `cherry-picked commits are followed by a soft reset, leaving all
changes as staged instead of as commits.`,
});
// TODO: Note that ideally we might do something similar to
// `git reset --merge`, but that would be (a) tricky and (b) it can fail,
// leaving the cherry-pick still in progress.
Expand Down Expand Up @@ -139,6 +145,11 @@ Could not resolve ${colors.red(commitish)} to a commit.`);
* @param {String[]} args.commit
*/
exports.executeableSubcommand = co.wrap(function *(args) {
const path = require("path");
const Reset = require("../util/reset");
const Hook = require("../util/hook");
const StatusUtil = require("../util/status_util");
const PrintStatusUtil = require("../util/print_status_util");
const CherryPickUtil = require("../util/cherry_pick_util");

const repo = yield GitUtil.getCurrentRepo();
Expand Down Expand Up @@ -178,4 +189,19 @@ exports.executeableSubcommand = co.wrap(function *(args) {
if (null !== result.errorMessage) {
throw new UserError(result.errorMessage);
}

if (args.no_commit) {
const commitish = `HEAD~${commits.length}`;
const annotated = yield GitUtil.resolveCommitish(repo, commitish);
const commit = yield repo.getCommit(annotated.id());
yield Reset.reset(repo, commit, Reset.TYPE.SOFT);

const repoStatus = yield StatusUtil.getRepoStatus(repo);
const cwd = process.cwd();
const relCwd = path.relative(repo.workdir(), cwd);
const statusText = PrintStatusUtil.printRepoStatus(repoStatus, relCwd);
process.stdout.write(statusText);

yield Hook.execHook(repo, "post-reset");
}
});

0 comments on commit b1e1908

Please sign in to comment.