From 97c2f6f040290b6befc42cb9cb67f65dcbb6e1ee Mon Sep 17 00:00:00 2001 From: James Ives Date: Fri, 17 May 2024 12:05:56 -0400 Subject: [PATCH] fix: test change --- src/worktree.ts | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/worktree.ts b/src/worktree.ts index 4230d3d20..3afbb7327 100644 --- a/src/worktree.ts +++ b/src/worktree.ts @@ -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 @@ -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(' ') + } } }