Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: determine if the branch exists first #1173

Merged
merged 3 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 37 additions & 3 deletions src/services/db/GitFileSystemService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,34 @@ export default class GitFileSystemService {
})
}

// Determine if the given branch is present in the local repo copy
isLocalBranchPresent(
repoName: string,
branchName: string
): ResultAsync<boolean, GitFileSystemError> {
const efsVolPath = this.getEfsVolPathFromBranch(branchName)
return ResultAsync.fromPromise(
this.git
.cwd({ path: `${efsVolPath}/${repoName}`, root: false })
.branchLocal(),
(error) => {
logger.error(
`Unable to get the list of local branches in ${efsVolPath}/${repoName}: ${JSON.stringify(
error
)}`
)

if (error instanceof GitError) {
return new GitFileSystemError(
"Unable to get the list of local branches"
)
}

return new GitFileSystemError("An unknown error occurred")
}
).map((result) => result.all.includes(branchName))
}

// Ensure that the repository is in the specified branch
ensureCorrectBranch(
repoName: string,
Expand Down Expand Up @@ -318,7 +346,7 @@ export default class GitFileSystemService {
.log([branchName]),
(error) => {
logger.error(
`Error when getting latest commit of "${branchName}" branch: ${error}, when trying to access ${efsVolPath}/${repoName} for ${branchName}`
`Error when getting Git log of "${branchName}" branch: ${error}, when trying to access ${efsVolPath}/${repoName} for ${branchName}`
)

if (error instanceof GitError) {
Expand Down Expand Up @@ -1610,8 +1638,14 @@ export default class GitFileSystemService {
repoName: string,
branchName: string
): ResultAsync<GitHubCommitData, GitFileSystemError> {
return this.getGitLog(repoName, branchName)
.orElse(() => this.getGitLog(repoName, `origin/${branchName}`))
return this.isLocalBranchPresent(repoName, branchName)
.andThen((isBranchLocallyPresent) => {
if (isBranchLocallyPresent) {
return this.getGitLog(repoName, branchName)
}

return this.getGitLog(repoName, `origin/${branchName}`)
})
.andThen((logSummary) => {
const possibleCommit = logSummary.latest
if (this.isDefaultLogFields(possibleCommit)) {
Expand Down
Loading
Loading