Skip to content

Commit 195da20

Browse files
authored
fix: prevent error if project do not have git (#19200)
1 parent 8561687 commit 195da20

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

packages/data-context/src/sources/GitDataSource.ts

+11-5
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,18 @@ export class GitDataSource {
120120
}
121121

122122
public async getBranch (absolutePath: string) {
123-
const { stdout, exitCode = 0 } = await execa(GIT_BRANCH_COMMAND, { shell: true, cwd: absolutePath })
123+
try {
124+
const { stdout, exitCode = 0 } = await execa(GIT_BRANCH_COMMAND, { shell: true, cwd: absolutePath })
125+
126+
this.ctx.debug('executing command `%s`:', GIT_BRANCH_COMMAND)
127+
this.ctx.debug('stdout for git branch', stdout)
128+
this.ctx.debug('exitCode for git branch', exitCode)
124129

125-
this.ctx.debug('executing command `%s`:', GIT_BRANCH_COMMAND)
126-
this.ctx.debug('stdout for git branch', stdout)
127-
this.ctx.debug('exitCode for git branch', exitCode)
130+
return exitCode === 0 ? stdout.trim() : null
131+
} catch (e) {
132+
this.ctx.debug('Error getting git branch: %s', (e as Error).message)
128133

129-
return exitCode === 0 ? stdout.trim() : null
134+
return null
135+
}
130136
}
131137
}

0 commit comments

Comments
 (0)