mirror of
https://code.forgejo.org/actions/git-backporting.git
synced 2025-06-04 20:34:30 -04:00
fix: abort conflicting cherry-pick before starting new one (#146)
Signed-off-by: Andrea Lamparelli <a.lamparelli95@gmail.com>
This commit is contained in:
parent
2b4b429356
commit
3deee59d4c
3 changed files with 66 additions and 0 deletions
|
@ -68,6 +68,15 @@ export default class GitCLIService {
|
|||
}
|
||||
|
||||
this.logger.info(`Folder ${to} already exist. Won't clone`);
|
||||
|
||||
// ensure the working tree is properly reset - no stale changes
|
||||
// from previous (failed) backport
|
||||
const ongoingCherryPick = await this.anyConflict(to);
|
||||
if (ongoingCherryPick) {
|
||||
this.logger.warn("Found previously failed cherry-pick, aborting it");
|
||||
await this.git(to).raw(["cherry-pick", "--abort"]);
|
||||
}
|
||||
|
||||
// checkout to the proper branch
|
||||
this.logger.info(`Checking out branch ${branch}`);
|
||||
await this.git(to).checkout(branch);
|
||||
|
@ -131,6 +140,21 @@ export default class GitCLIService {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether there are some conflicts in the current working directory
|
||||
* which means there is an ongoing cherry-pick that did not complete successfully
|
||||
* @param cwd repository in which the check should be performed
|
||||
* @return true if there is some conflict, false otherwise
|
||||
*/
|
||||
async anyConflict(cwd: string): Promise<boolean> {
|
||||
const status = await this.git(cwd).status();
|
||||
if (status.conflicted.length > 0) {
|
||||
this.logger.debug(`Found conflicts in branch ${status.current}`);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Push a branch to a remote
|
||||
* @param cwd repository in which the push should be performed
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue