Skip to content

Commit 44a21fd

Browse files
committed
Fixed copilot comments
1 parent bf28276 commit 44a21fd

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

pkg/github/repositories.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,7 +1290,9 @@ func PushFiles(t translations.TranslationHelperFunc) inventory.ServerTool {
12901290
} else if ghErr.Response.StatusCode == http.StatusNotFound {
12911291
branchNotFound = true
12921292
}
1293-
} else {
1293+
}
1294+
1295+
if !repositoryIsEmpty && !branchNotFound {
12941296
return ghErrors.NewGitHubAPIErrorResponse(ctx,
12951297
"failed to get branch reference",
12961298
resp,
@@ -1331,7 +1333,8 @@ func PushFiles(t translations.TranslationHelperFunc) inventory.ServerTool {
13311333
return utils.NewToolResultError(fmt.Sprintf("failed to initialize repository: %v", err)), nil, nil
13321334
}
13331335

1334-
if branch != (*defaultRef.Ref)[len("refs/heads/"):] {
1336+
defaultBranch := strings.TrimPrefix(*defaultRef.Ref, "refs/heads/")
1337+
if branch != defaultBranch {
13351338
// Create the requested branch from the default branch
13361339
ref, err = createReferenceFromDefaultBranch(ctx, client, owner, repo, branch)
13371340
if err != nil {
@@ -1489,7 +1492,7 @@ func createReferenceFromDefaultBranch(ctx context.Context, client *github.Client
14891492

14901493
// Create the new branch reference
14911494
createdRef, resp, err := client.Git.CreateRef(ctx, owner, repo, github.CreateRef{
1492-
Ref: *github.Ptr("refs/heads/" + branch),
1495+
Ref: "refs/heads/" + branch,
14931496
SHA: *defaultRef.Object.SHA,
14941497
})
14951498
if err != nil {

0 commit comments

Comments
 (0)