mirror of
https://code.forgejo.org/actions/git-backporting.git
synced 2025-02-22 10:35:43 -05: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
21
dist/cli/index.js
vendored
21
dist/cli/index.js
vendored
|
@ -541,6 +541,13 @@ class GitCLIService {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.logger.info(`Folder ${to} already exist. Won't clone`);
|
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
|
// checkout to the proper branch
|
||||||
this.logger.info(`Checking out branch ${branch}`);
|
this.logger.info(`Checking out branch ${branch}`);
|
||||||
await this.git(to).checkout(branch);
|
await this.git(to).checkout(branch);
|
||||||
|
@ -598,6 +605,20 @@ class GitCLIService {
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 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) {
|
||||||
|
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
|
* Push a branch to a remote
|
||||||
* @param cwd repository in which the push should be performed
|
* @param cwd repository in which the push should be performed
|
||||||
|
|
21
dist/gha/index.js
vendored
21
dist/gha/index.js
vendored
|
@ -506,6 +506,13 @@ class GitCLIService {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.logger.info(`Folder ${to} already exist. Won't clone`);
|
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
|
// checkout to the proper branch
|
||||||
this.logger.info(`Checking out branch ${branch}`);
|
this.logger.info(`Checking out branch ${branch}`);
|
||||||
await this.git(to).checkout(branch);
|
await this.git(to).checkout(branch);
|
||||||
|
@ -563,6 +570,20 @@ class GitCLIService {
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 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) {
|
||||||
|
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
|
* Push a branch to a remote
|
||||||
* @param cwd repository in which the push should be performed
|
* @param cwd repository in which the push should be performed
|
||||||
|
|
|
@ -68,6 +68,15 @@ export default class GitCLIService {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.logger.info(`Folder ${to} already exist. Won't clone`);
|
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
|
// checkout to the proper branch
|
||||||
this.logger.info(`Checking out branch ${branch}`);
|
this.logger.info(`Checking out branch ${branch}`);
|
||||||
await this.git(to).checkout(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
|
* Push a branch to a remote
|
||||||
* @param cwd repository in which the push should be performed
|
* @param cwd repository in which the push should be performed
|
||||||
|
|
Loading…
Add table
Reference in a new issue