Skip to content

Commit

Permalink
fix: test change
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesIves committed May 17, 2024
1 parent 1a64cb8 commit 97c2f6f
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/worktree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ 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 @@ -11,13 +12,21 @@ export class GitCheckout {
this.branch = branch
}
toString(): string {
return [
'git',
'checkout',
this.orphan ? '--orphan' : '-B',
this.branch,
this.commitish || ''
].join(' ')
// 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(' ')
}
}
}

Expand Down

0 comments on commit 97c2f6f

Please sign in to comment.