Skip to content

Commit

Permalink
t
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesIves committed May 17, 2024
1 parent 15e706b commit 6138e5c
Showing 1 changed file with 12 additions and 29 deletions.
41 changes: 12 additions & 29 deletions src/worktree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {info} from '@actions/core'
import {ActionInterface} from './constants'
import {execute} from './execute'
import {extractErrorMessage, suppressSensitiveInformation} from './util'
import {execSync} from 'child_process';

export class GitCheckout {
orphan = false
Expand All @@ -12,21 +11,13 @@ export class GitCheckout {
this.branch = branch
}
toString(): string {
// Check if the branch is already checked out in another worktree
try {
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(' ')
}
}

Expand All @@ -49,19 +40,11 @@ export async function generateWorktree(
)
}

// Check if the branch is already checked out in another worktree
try {
execSync(`git rev-parse --verify --quiet ${action.branch}`);
// If the command succeeds, the branch is already checked out
info(`Branch ${action.branch} is already checked out. Using existing worktree.`)
} catch (error) {
// If the command fails, the branch is not checked out
await 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)

Expand Down

0 comments on commit 6138e5c

Please sign in to comment.