mirror of
https://github.com/outbackdingo/ghorg.git
synced 2026-01-27 10:19:03 +00:00
Change default behavior of gitlab repo name collisions (#239)
This commit is contained in:
@@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file.
|
||||
|
||||
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
||||
|
||||
## [1.8.6] - unreleased
|
||||
### Added
|
||||
### Changed
|
||||
- Default behavior of gitlab repo naming collisions to append namespace'd path to repo name instead of auto adding preserve dir behavior; thanks @sding3
|
||||
### Deprecated
|
||||
### Removed
|
||||
### Fixed
|
||||
### Security
|
||||
## [1.8.5] - 7/13/22
|
||||
### Added
|
||||
- GHORG_GIT_FILTER flag to clone command; thanks @ryanaross
|
||||
|
||||
@@ -117,7 +117,7 @@ go get github.com/gabrie30/ghorg
|
||||
|
||||
#### GitLab Specific Notes
|
||||
|
||||
1. With GitLab, if ghorg detects repo naming collisions with repos being cloned from different groups/subgroups, ghorg will automatically add the `--presever-dir` flag on your behalf and all repos will be cloned into a directory structure that matches your groups/subgroups, instead of all repos into one directory. You will be notified in the output if this occurs.
|
||||
1. With GitLab, if ghorg detects repo naming collisions with repos being cloned from different groups/subgroups, ghorg will automatically append the group/subgroup path to the repo name. You will be notified in the output if this occurs.
|
||||
|
||||
1. There are different commands for hosted gitlab instances vs gitlab cloud read below for the differences.
|
||||
|
||||
|
||||
35
cmd/clone.go
35
cmd/clone.go
@@ -411,26 +411,30 @@ func getRepoCountOnly(targets []scm.Repo) int {
|
||||
return count
|
||||
}
|
||||
|
||||
// Needed bc https://github.com/gabrie30/ghorg/issues/225
|
||||
func hasRepoNameCollisions(repos []scm.Repo) bool {
|
||||
func hasRepoNameCollisions(repos []scm.Repo) (map[string]bool, bool) {
|
||||
|
||||
repoNameWithCollisions := make(map[string]bool)
|
||||
|
||||
if os.Getenv("GHORG_GITLAB_TOKEN") == "" {
|
||||
return false
|
||||
return repoNameWithCollisions, false
|
||||
}
|
||||
|
||||
if os.Getenv("GHORG_PRESERVE_DIRECTORY_STRUCTURE") == "true" {
|
||||
return false
|
||||
return repoNameWithCollisions, false
|
||||
}
|
||||
|
||||
repoNamesSeen := make(map[string]string)
|
||||
hasCollisions := false
|
||||
|
||||
for _, repo := range repos {
|
||||
if _, ok := repoNamesSeen[repo.Name]; ok {
|
||||
return true
|
||||
if _, ok := repoNameWithCollisions[repo.Name]; ok {
|
||||
repoNameWithCollisions[repo.Name] = true
|
||||
hasCollisions = true
|
||||
} else {
|
||||
repoNameWithCollisions[repo.Name] = false
|
||||
}
|
||||
repoNamesSeen[repo.Name] = "seen"
|
||||
}
|
||||
|
||||
return false
|
||||
return repoNameWithCollisions, hasCollisions
|
||||
}
|
||||
|
||||
func printDryRun(repos []scm.Repo) {
|
||||
@@ -533,7 +537,7 @@ func CloneAllRepos(git git.Gitter, cloneTargets []scm.Repo) {
|
||||
createDirIfNotExist()
|
||||
|
||||
// check for duplicate names will cause issues for some clone types on gitlab
|
||||
hasCollisions := hasRepoNameCollisions(cloneTargets)
|
||||
repoNameWithCollisions, hasCollisions := hasRepoNameCollisions(cloneTargets)
|
||||
|
||||
l, err := strconv.Atoi(os.Getenv("GHORG_CONCURRENCY"))
|
||||
if err != nil {
|
||||
@@ -551,11 +555,10 @@ func CloneAllRepos(git git.Gitter, cloneTargets []scm.Repo) {
|
||||
if repo.Path != "" && os.Getenv("GHORG_PRESERVE_DIRECTORY_STRUCTURE") == "true" {
|
||||
repoSlug = repo.Path
|
||||
}
|
||||
|
||||
// if there are collisions the repos need to be clone like --preserve-dir is enabled
|
||||
if hasCollisions {
|
||||
os.Setenv("GHORG_PRESERVE_DIRECTORY_STRUCTURE", "true")
|
||||
repoSlug = repo.Path
|
||||
// Only GitLab repos can have collisions due to groups and subgroups
|
||||
// If there are collisions and this is a repo with a naming collision change name to avoid collisions
|
||||
if hasCollisions && repoNameWithCollisions[repo.Name] {
|
||||
repoSlug = strings.Replace(repo.Path, "/", "_", -1)
|
||||
}
|
||||
|
||||
repo.HostPath = filepath.Join(outputDirAbsolutePath, repoSlug)
|
||||
@@ -709,7 +712,7 @@ func CloneAllRepos(git git.Gitter, cloneTargets []scm.Repo) {
|
||||
|
||||
if hasCollisions {
|
||||
fmt.Println("")
|
||||
colorlog.PrintInfo("ATTENTION: ghorg detected collisions in repo names from the groups that were cloned. This occurs when one or more groups share common repo names. Cloning all repos to one flat directoy would cause issues, so the --preserve-dir flag was automatically enabled on your behalf. This will result in the repos being clone into their respective group folders. To prevent this from happening you can clone more specific groups/subgroups or use the --preserve-dir flag when cloning.")
|
||||
colorlog.PrintInfo("ATTENTION: ghorg detected collisions in repo names from the groups that were cloned. This occurs when one or more groups share common repo names trying to be cloned to the same directory. The repos that would have collisions were renamed with the group/subgroup appended.")
|
||||
}
|
||||
|
||||
// Now, clean up local repos that don't exist in remote, if prune flag is set
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
const ghorgVersion = "v1.8.5"
|
||||
const ghorgVersion = "v1.8.6"
|
||||
|
||||
var versionCmd = &cobra.Command{
|
||||
Use: "version",
|
||||
|
||||
@@ -9,3 +9,13 @@ TODO: Do the same for the community edition of GitLab
|
||||
If running locally you'll also need to update your /etc/hosts
|
||||
|
||||
`echo "127.0.0.1 gitlab.example.com" >> /etc/hosts`
|
||||
|
||||
Once github is running you can vist
|
||||
|
||||
http://gitlab.example.com in your browser
|
||||
|
||||
You can get the root token by running
|
||||
|
||||
```
|
||||
docker exec -it gitlab grep 'Password:' /etc/gitlab/initial_root_password | awk '{print $2}'
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user