Skip to content

Commit

Permalink
Merge branch 'releases/v4-worktree' of https://github.com/JamesIves/g…
Browse files Browse the repository at this point in the history
…ithub-pages-deploy-action into releases/v4-worktree
  • Loading branch information
JamesIves committed May 17, 2024
2 parents b309c94 + 515358d commit b952651
Showing 1 changed file with 12 additions and 27 deletions.
39 changes: 12 additions & 27 deletions lib/worktree.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,20 @@ exports.generateWorktree = exports.GitCheckout = void 0;
const core_1 = require("@actions/core");
const execute_1 = require("./execute");
const util_1 = require("./util");
const child_process_1 = require("child_process");
class GitCheckout {
constructor(branch) {
this.orphan = false;
this.commitish = null;
this.branch = branch;
}
toString() {
// Check if the branch is already checked out in another worktree
try {
(0, child_process_1.execSync)(`git rev-parse --verify --quiet ${this.branch}`);
// If the command succeeds, the branch is already checked out
return `git checkout ${this.branch}`;
}
catch (error) {
// If the command fails, the branch is not checked out
return [
'git',
'checkout',
this.orphan ? '--orphan' : '-B',
this.branch,
this.commitish || ''
].join(' ');
}
return [
'git',
'checkout',
this.orphan ? '--orphan' : '-B',
this.branch,
this.commitish || ''
].join(' ');
}
}
exports.GitCheckout = GitCheckout;
Expand All @@ -50,16 +40,11 @@ function generateWorktree(action, worktreedir, branchExists) {
if (branchExists) {
yield (0, execute_1.execute)(`git fetch --no-recurse-submodules --depth=1 origin ${action.branch}`, action.workspace, action.silent);
}
// Check if the branch is already checked out in another worktree
try {
(0, child_process_1.execSync)(`git rev-parse --verify --quiet ${action.branch}`);
// If the command succeeds, the branch is already checked out
(0, core_1.info)(`Branch ${action.branch} is already checked out. Using existing worktree.`);
}
catch (error) {
// If the command fails, the branch is not checked out
yield (0, execute_1.execute)(`git worktree add --no-checkout --detach ${worktreedir}`, action.workspace, action.silent);
}
// await execute(
// `git worktree add --no-checkout --detach ${worktreedir}`,
// action.workspace,
// action.silent
// )
const checkout = new GitCheckout(action.branch);
if (branchExists) {
// There's existing data on the branch to check out
Expand Down

0 comments on commit b952651

Please sign in to comment.