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
|
@ -22,12 +22,18 @@ import (
|
|||
type GitImporter struct {
|
||||
li LocalImporter
|
||||
Remote string
|
||||
Branch string
|
||||
}
|
||||
|
||||
func NewGitImporter(li LocalImporter, remote string) GitImporter {
|
||||
func NewGitImporter(li LocalImporter, remote string, branch string) GitImporter {
|
||||
if len(branch) == 0 {
|
||||
branch = "master"
|
||||
}
|
||||
|
||||
return GitImporter{
|
||||
li: li,
|
||||
Remote: remote,
|
||||
Branch: branch,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -62,8 +68,14 @@ func (i GitImporter) Init() error {
|
|||
if n, err := countFileInDir(i.li.Base); err != nil {
|
||||
return err
|
||||
} else if n == 0 {
|
||||
args := []string{"clone", "--recursive", "--depth", "1"}
|
||||
if i.Branch != "" {
|
||||
args = append(args, "-b", i.Branch)
|
||||
}
|
||||
args = append(args, "--shallow-submodules", i.Remote, i.li.Base)
|
||||
|
||||
log.Println("Please wait while creating the local git repository...")
|
||||
cmdclone := exec.Command("git", "clone", "--recursive", "--depth", "1", "--shallow-submodules", i.Remote, i.li.Base)
|
||||
cmdclone := exec.Command("git", args...)
|
||||
stdout, err := cmdclone.CombinedOutput()
|
||||
if err != nil {
|
||||
return fmt.Errorf("%w:\n%s", err, stdout)
|
||||
|
@ -109,7 +121,7 @@ func (i GitImporter) Sync() error {
|
|||
}
|
||||
}
|
||||
|
||||
cmdreset := exec.Command("git", "-C", i.li.Base, "reset", "--hard", "--recurse-submodule", "origin/master")
|
||||
cmdreset := exec.Command("git", "-C", i.li.Base, "reset", "--hard", "--recurse-submodule", "origin/"+i.Branch)
|
||||
stdout, err = cmdreset.CombinedOutput()
|
||||
if err != nil {
|
||||
log.Printf("Local git repository reset failed: %s\n%s", err, stdout)
|
||||
|
|
Reference in a new issue