diff --git a/devel-importer/main.go b/devel-importer/main.go index 77caa71..ba82e31 100644 --- a/devel-importer/main.go +++ b/devel-importer/main.go @@ -146,7 +146,9 @@ func listMaintainers(obs *common.ObsClient, prj string, pkgs []string) { log.Panicln(err) } - contact_email = append(contact_email, fmt.Sprintf("%s <%s>", user.Name, user.Email)) + if user != nil { + contact_email = append(contact_email, fmt.Sprintf("%s <%s>", user.Name, user.Email)) + } } log.Println(strings.Join(contact_email, ", ")) } @@ -409,6 +411,9 @@ func importDevelRepoAndCheckHistory(pkg string, meta *common.PackageMeta) *model if err2 := cloneDevel(git, "", pkg, meta.ScmSync, "origin", true); err2 != nil { log.Panicln(err2) } + if len(u.Fragment) == 0 { + u.Fragment = "HEAD" + } git.GitExecOrPanic(pkg, "checkout", "-B", "main", u.Fragment) } common.LogDebug("skip check for scmsync") @@ -454,6 +459,24 @@ func importDevelRepoAndCheckHistory(pkg string, meta *common.PackageMeta) *model return repo } + return repo +} + +func SetMainBranch(pkg string) { + // scnsync, follow that and don't care + remotes := common.SplitStringNoEmpty(git.GitExecWithOutputOrPanic(pkg, "remote", "show"), "\n") + if slices.Contains(remotes, "origin") { + git.GitExecOrPanic(pkg, "checkout", "-B", "main", "origin/HEAD") + return + } + + // check if we have factory + if _, err := git.GitBranchHead(pkg, "factory"); err != nil { + if len(git.GitExecWithOutputOrPanic(pkg, "show-ref", "pool/factory")) > 20 { + git.GitExecOrPanic(pkg, "branch", "factory", "pool/factory") + } + } + // mark newer branch as main branch := "factory" if len(common.SplitStringNoEmpty(git.GitExecWithOutputOrPanic(pkg, "rev-list", "^factory", "devel"), "\n")) > 0 { @@ -461,7 +484,6 @@ func importDevelRepoAndCheckHistory(pkg string, meta *common.PackageMeta) *model } common.LogInfo("setting main to", branch) git.GitExecOrPanic(pkg, "checkout", "-B", "main", branch) - return repo } func ObsToRepoName(obspkg string) string { @@ -500,6 +522,7 @@ func importRepo(pkg string) (BrokenFactoryPackage, FailedImport bool) { develRepo = importDevelRepoAndCheckHistory(pkg, meta) } + SetMainBranch(pkg) PushRepository(factoryRepo, develRepo, pkg) return }