From ab4d1d6a7e767dcceb88a6349e75dad57e4388a7 Mon Sep 17 00:00:00 2001 From: Massaki Archambault Date: Mon, 18 Jan 2021 00:24:26 -0500 Subject: [PATCH] fix default initial branch ignoring the project default branch and always be set to master --- fs/repository.go | 2 +- git/clone.go | 5 ++++- gitlab/project.go | 15 ++++++++++----- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/fs/repository.go b/fs/repository.go index 0bfe05e..5370473 100644 --- a/fs/repository.go +++ b/fs/repository.go @@ -29,7 +29,7 @@ func newRepositoryNode(project *gitlab.Project, param *FSParam) (*RepositoryNode func (n *RepositoryNode) Readlink(ctx context.Context) ([]byte, syscall.Errno) { // Create the local copy of the repo - localRepoLoc, _ := n.param.Git.CloneOrPull(n.project.CloneURL, n.project.ID, "master") + localRepoLoc, _ := n.param.Git.CloneOrPull(n.project.CloneURL, n.project.ID, n.project.DefaultBranch) return []byte(localRepoLoc), 0 } diff --git a/git/clone.go b/git/clone.go index 8835d5a..33a4f29 100644 --- a/git/clone.go +++ b/git/clone.go @@ -82,9 +82,12 @@ func (c *gitClient) clone(gcp *gitCloneParam) error { if err != nil { return fmt.Errorf("failed to retrieve worktree of git repo %v: %v", gcp.dst, err) } - w.Checkout(&git.CheckoutOptions{ + err = w.Checkout(&git.CheckoutOptions{ Branch: branchRef, }) + if err != nil { + return fmt.Errorf("failed to checkout %v of git repo %v: %v", branchRef, gcp.dst, err) + } } if c.PullAfterClone { // Dispatch to pull worker diff --git a/gitlab/project.go b/gitlab/project.go index 7432bab..6f789f5 100644 --- a/gitlab/project.go +++ b/gitlab/project.go @@ -5,16 +5,21 @@ import ( ) type Project struct { - ID int - Name string - CloneURL string + ID int + Name string + CloneURL string + DefaultBranch string } func (c *gitlabClient) newProjectFromGitlabProject(project *gitlab.Project) Project { // https://godoc.org/github.com/xanzy/go-gitlab#Project p := Project{ - ID: project.ID, - Name: project.Path, + ID: project.ID, + Name: project.Path, + DefaultBranch: project.DefaultBranch, + } + if p.DefaultBranch == "" { + p.DefaultBranch = "master" } if c.PullMethod == PullMethodSSH { p.CloneURL = project.SSHURLToRepo