Skip to content

Commit

Permalink
feat: enhance error handling for non-git directories
Browse files Browse the repository at this point in the history
- Improve error message for the case when .git directory is not found in the given working directory
- Add a warning message when the current working directory is not inside a git repository
  • Loading branch information
jackton1 committed Jan 25, 2024
1 parent 2cb2c92 commit dcf1ea7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,8 @@ export async function run(): Promise<void> {
})
} else {
if (!hasGitDirectory) {
core.info(`Running on a ${github.context.eventName} event...`)
throw new Error(
`Can't find local .git in ${workingDirectory} directory. Please run actions/checkout before this action (Make sure the 'path' input is correct). If you intend to use Github's REST API note that only pull_request* events are supported.`
`Unable to locate the git repository in the given path: ${workingDirectory}.\n Please run actions/checkout before this action (Make sure the 'path' input is correct).\n If you intend to use Github's REST API note that only pull_request* events are supported. Current event is "${github.context.eventName}".`
)
}

Expand Down
6 changes: 6 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,12 @@ export const isInsideWorkTree = async ({
}
)

if (stdout.trim() !== 'true') {
core.warning(
`The current working directory is not inside a git repository: ${cwd}`
)
}

return stdout.trim() === 'true'
}

Expand Down

0 comments on commit dcf1ea7

Please sign in to comment.