feat(issue-62): make cherry-pick strategy configurable (#63)

fix https://github.com/kiegroup/git-backporting/issues/62
This commit is contained in:
Andrea Lamparelli 2023-07-12 13:50:59 +02:00 committed by GitHub
parent ead1322c0f
commit 265955dda7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 312 additions and 58 deletions

View file

@ -105,9 +105,20 @@ export default class GitCLIService {
* @param cwd repository in which the sha should be cherry picked to
* @param sha commit sha
*/
async cherryPick(cwd: string, sha: string): Promise<void> {
async cherryPick(cwd: string, sha: string, strategy = "recursive", strategyOption = "theirs"): Promise<void> {
this.logger.info(`Cherry picking ${sha}.`);
await this.git(cwd).raw(["cherry-pick", "-m", "1", "--strategy=recursive", "--strategy-option=theirs", sha]);
const options = ["cherry-pick", "-m", "1", `--strategy=${strategy}`, `--strategy-option=${strategyOption}`, sha];
try {
await this.git(cwd).raw(options);
} catch(error) {
const diff = await this.git(cwd).diff();
if (diff) {
throw new Error(`${error}\r\nShowing git diff:\r\n` + diff);
}
throw error;
}
}
/**