admin: New option to pass branch to use
This commit is contained in:
parent
f623699f56
commit
f5529ff72d
3 changed files with 25 additions and 5 deletions
|
|
@ -11,6 +11,7 @@ import (
|
|||
|
||||
"github.com/go-git/go-git/v5"
|
||||
"github.com/go-git/go-git/v5/config"
|
||||
"github.com/go-git/go-git/v5/plumbing"
|
||||
"github.com/go-git/go-git/v5/plumbing/transport/ssh"
|
||||
)
|
||||
|
||||
|
|
@ -19,10 +20,11 @@ import (
|
|||
type GitImporter struct {
|
||||
li LocalImporter
|
||||
Remote string
|
||||
Branch string
|
||||
Auth ssh.AuthMethod
|
||||
}
|
||||
|
||||
func NewGitImporter(li LocalImporter, remote string) GitImporter {
|
||||
func NewGitImporter(li LocalImporter, remote string, branch string) GitImporter {
|
||||
var auth ssh.AuthMethod
|
||||
|
||||
// If there is no ssh-agent setup, try to use a default ssh key
|
||||
|
|
@ -47,6 +49,7 @@ func NewGitImporter(li LocalImporter, remote string) GitImporter {
|
|||
return GitImporter{
|
||||
li: li,
|
||||
Remote: remote,
|
||||
Branch: branch,
|
||||
Auth: auth,
|
||||
}
|
||||
}
|
||||
|
|
@ -76,6 +79,7 @@ func (i GitImporter) Init() error {
|
|||
} else if n == 0 {
|
||||
_, err = git.PlainClone(i.li.Base, false, &git.CloneOptions{
|
||||
URL: i.Remote,
|
||||
ReferenceName: plumbing.ReferenceName(i.Branch),
|
||||
RecurseSubmodules: git.DefaultSubmoduleRecursionDepth,
|
||||
Auth: i.Auth,
|
||||
})
|
||||
|
|
@ -116,6 +120,7 @@ func (i GitImporter) Sync() error {
|
|||
// Perform a git pull --rebase origin/master
|
||||
err = w.Pull(&git.PullOptions{
|
||||
RemoteName: "origin",
|
||||
ReferenceName: plumbing.ReferenceName(i.Branch),
|
||||
Depth: 1,
|
||||
RecurseSubmodules: git.DefaultSubmoduleRecursionDepth,
|
||||
Force: true,
|
||||
|
|
|
|||
Reference in a new issue