admin: New option to pass branch to use
This commit is contained in:
parent
f623699f56
commit
f5529ff72d
@ -66,6 +66,7 @@ func main() {
|
|||||||
cloudPassword := ""
|
cloudPassword := ""
|
||||||
localImporterDirectory := ""
|
localImporterDirectory := ""
|
||||||
gitImporterRemote := ""
|
gitImporterRemote := ""
|
||||||
|
gitImporterBranch := ""
|
||||||
localImporterSymlink := false
|
localImporterSymlink := false
|
||||||
baseURL := "/"
|
baseURL := "/"
|
||||||
checkplugins := sync.CheckPluginList{}
|
checkplugins := sync.CheckPluginList{}
|
||||||
@ -113,6 +114,8 @@ func main() {
|
|||||||
"Copy files or just create symlink?")
|
"Copy files or just create symlink?")
|
||||||
flag.StringVar(&gitImporterRemote, "git-import-remote", gitImporterRemote,
|
flag.StringVar(&gitImporterRemote, "git-import-remote", gitImporterRemote,
|
||||||
"Remote URL of the git repository to use as synchronization source")
|
"Remote URL of the git repository to use as synchronization source")
|
||||||
|
flag.StringVar(&gitImporterBranch, "git-branch", gitImporterBranch,
|
||||||
|
"Branch to use in the git repository")
|
||||||
flag.StringVar(&cloudDAVBase, "clouddav", cloudDAVBase,
|
flag.StringVar(&cloudDAVBase, "clouddav", cloudDAVBase,
|
||||||
"Base directory where found challenges files to import, cloud part")
|
"Base directory where found challenges files to import, cloud part")
|
||||||
flag.StringVar(&cloudUsername, "clouduser", cloudUsername, "Username used to sync")
|
flag.StringVar(&cloudUsername, "clouduser", cloudUsername, "Username used to sync")
|
||||||
@ -133,7 +136,7 @@ func main() {
|
|||||||
log.Fatal("Cannot have both --clouddav and --git-import-remote defined.")
|
log.Fatal("Cannot have both --clouddav and --git-import-remote defined.")
|
||||||
return
|
return
|
||||||
} else if gitImporterRemote != "" {
|
} else if gitImporterRemote != "" {
|
||||||
sync.GlobalImporter = sync.NewGitImporter(sync.LocalImporter{Base: localImporterDirectory, Symlink: localImporterSymlink}, gitImporterRemote)
|
sync.GlobalImporter = sync.NewGitImporter(sync.LocalImporter{Base: localImporterDirectory, Symlink: localImporterSymlink}, gitImporterRemote, gitImporterBranch)
|
||||||
} else if localImporterDirectory != "" {
|
} else if localImporterDirectory != "" {
|
||||||
sync.GlobalImporter = sync.LocalImporter{Base: localImporterDirectory, Symlink: localImporterSymlink}
|
sync.GlobalImporter = sync.LocalImporter{Base: localImporterDirectory, Symlink: localImporterSymlink}
|
||||||
} else if cloudDAVBase != "" {
|
} else if cloudDAVBase != "" {
|
||||||
|
@ -11,6 +11,7 @@ import (
|
|||||||
|
|
||||||
"github.com/go-git/go-git/v5"
|
"github.com/go-git/go-git/v5"
|
||||||
"github.com/go-git/go-git/v5/config"
|
"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"
|
"github.com/go-git/go-git/v5/plumbing/transport/ssh"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -19,10 +20,11 @@ import (
|
|||||||
type GitImporter struct {
|
type GitImporter struct {
|
||||||
li LocalImporter
|
li LocalImporter
|
||||||
Remote string
|
Remote string
|
||||||
|
Branch string
|
||||||
Auth ssh.AuthMethod
|
Auth ssh.AuthMethod
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewGitImporter(li LocalImporter, remote string) GitImporter {
|
func NewGitImporter(li LocalImporter, remote string, branch string) GitImporter {
|
||||||
var auth ssh.AuthMethod
|
var auth ssh.AuthMethod
|
||||||
|
|
||||||
// If there is no ssh-agent setup, try to use a default ssh key
|
// 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{
|
return GitImporter{
|
||||||
li: li,
|
li: li,
|
||||||
Remote: remote,
|
Remote: remote,
|
||||||
|
Branch: branch,
|
||||||
Auth: auth,
|
Auth: auth,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -76,6 +79,7 @@ func (i GitImporter) Init() error {
|
|||||||
} else if n == 0 {
|
} else if n == 0 {
|
||||||
_, err = git.PlainClone(i.li.Base, false, &git.CloneOptions{
|
_, err = git.PlainClone(i.li.Base, false, &git.CloneOptions{
|
||||||
URL: i.Remote,
|
URL: i.Remote,
|
||||||
|
ReferenceName: plumbing.ReferenceName(i.Branch),
|
||||||
RecurseSubmodules: git.DefaultSubmoduleRecursionDepth,
|
RecurseSubmodules: git.DefaultSubmoduleRecursionDepth,
|
||||||
Auth: i.Auth,
|
Auth: i.Auth,
|
||||||
})
|
})
|
||||||
@ -116,6 +120,7 @@ func (i GitImporter) Sync() error {
|
|||||||
// Perform a git pull --rebase origin/master
|
// Perform a git pull --rebase origin/master
|
||||||
err = w.Pull(&git.PullOptions{
|
err = w.Pull(&git.PullOptions{
|
||||||
RemoteName: "origin",
|
RemoteName: "origin",
|
||||||
|
ReferenceName: plumbing.ReferenceName(i.Branch),
|
||||||
Depth: 1,
|
Depth: 1,
|
||||||
RecurseSubmodules: git.DefaultSubmoduleRecursionDepth,
|
RecurseSubmodules: git.DefaultSubmoduleRecursionDepth,
|
||||||
Force: true,
|
Force: true,
|
||||||
|
@ -22,12 +22,18 @@ import (
|
|||||||
type GitImporter struct {
|
type GitImporter struct {
|
||||||
li LocalImporter
|
li LocalImporter
|
||||||
Remote string
|
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{
|
return GitImporter{
|
||||||
li: li,
|
li: li,
|
||||||
Remote: remote,
|
Remote: remote,
|
||||||
|
Branch: branch,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,8 +68,14 @@ func (i GitImporter) Init() error {
|
|||||||
if n, err := countFileInDir(i.li.Base); err != nil {
|
if n, err := countFileInDir(i.li.Base); err != nil {
|
||||||
return err
|
return err
|
||||||
} else if n == 0 {
|
} 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...")
|
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()
|
stdout, err := cmdclone.CombinedOutput()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("%w:\n%s", err, stdout)
|
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()
|
stdout, err = cmdreset.CombinedOutput()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Local git repository reset failed: %s\n%s", err, stdout)
|
log.Printf("Local git repository reset failed: %s\n%s", err, stdout)
|
||||||
|
Loading…
Reference in New Issue
Block a user