Skip to content

Commit 6042a9a

Browse files
committed
add error reporting exclusion for invalid git repo if init repo option is selected
1 parent e8416d5 commit 6042a9a

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

api/add_repo.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ func AddRepo(inputs model.NewRepoInputs) *model.AddRepoParams {
160160

161161
_, invalidRepoErr := git.RepoValidator(repoPath)
162162

163-
if invalidRepoErr != nil {
163+
if invalidRepoErr != nil && !initSwitch {
164164
localLogger(fmt.Sprintf("The repo is not a valid git repo\n%v", invalidRepoErr), global.StatusError)
165165

166166
return &model.AddRepoParams{

git/git_branch_add.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,21 @@ import (
1111

1212
func AddBranch(repo *git.Repository, branchName string) string {
1313
logger := global.Logger{}
14-
headRef, _ := repo.Head()
15-
ref := plumbing.NewHashReference(plumbing.ReferenceName(fmt.Sprintf("refs/heads/%v", branchName)), headRef.Hash())
16-
branchErr := repo.Storer.SetReference(ref)
14+
headRef, headErr := repo.Head()
1715

18-
if branchErr != nil {
19-
logger.Log(fmt.Sprintf("Failed to add branch - %s - %s", branchName, branchErr.Error()), global.StatusError)
16+
if headErr != nil {
17+
logger.Log(fmt.Sprintf("Unable to fetch HEAD -> %s", headErr.Error()), global.StatusError)
2018
return "BRANCH_ADD_FAILED"
21-
}
19+
} else {
20+
ref := plumbing.NewHashReference(plumbing.ReferenceName(fmt.Sprintf("refs/heads/%v", branchName)), headRef.Hash())
21+
branchErr := repo.Storer.SetReference(ref)
22+
23+
if branchErr != nil {
24+
logger.Log(fmt.Sprintf("Failed to add branch - %s - %s", branchName, branchErr.Error()), global.StatusError)
25+
return "BRANCH_ADD_FAILED"
26+
}
2227

23-
logger.Log(fmt.Sprintf("Added new branch - %s to the repo", branchName), global.StatusInfo)
24-
return "BRANCH_CREATION_SUCCESS"
28+
logger.Log(fmt.Sprintf("Added new branch - %s to the repo", branchName), global.StatusInfo)
29+
return "BRANCH_CREATION_SUCCESS"
30+
}
2531
}

graph/schema.resolvers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ func (r *queryResolver) BranchCompare(ctx context.Context, repoID string, baseBr
334334
if head, _ := repo.GitRepo.Head(); repo.GitRepo == nil || head == nil {
335335
return []*model.BranchCompareResults{
336336
{
337-
Date: "",
337+
Date: "",
338338
Commits: nil,
339339
},
340340
}, nil

0 commit comments

Comments
 (0)