From bb780ef2a1edce7d722b4eeaee2fa04bd4c909cc Mon Sep 17 00:00:00 2001 From: Jay Gabriels Date: Sun, 28 Aug 2022 09:18:22 -0700 Subject: [PATCH] Add filename length limit on gitlab repos with name collisions (#242) --- CHANGELOG.md | 9 +++++++++ cmd/clone.go | 18 +++++++++++++++++- cmd/version.go | 2 +- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c5aef0..16a62f4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,15 @@ 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.8] - unreleased +### Added +- Filename length limit on gitlab repos with name collisions +### Changed +### Deprecated +### Removed +### Fixed +### Security + ## [1.8.7] - 7/19/22 ### Added ### Changed diff --git a/cmd/clone.go b/cmd/clone.go index 7a8413c..ba46e6d 100644 --- a/cmd/clone.go +++ b/cmd/clone.go @@ -470,6 +470,15 @@ func printDryRun(repos []scm.Repo) { } } +func trimCollisionFilename(filename string) string { + maxLen := 248 + if len(filename) > maxLen { + return filename[:strings.LastIndex(filename[:maxLen], "_")] + } + + return filename +} + // CloneAllRepos clones all repos func CloneAllRepos(git git.Gitter, cloneTargets []scm.Repo) { // Filter repos that have attributes that don't need specific scm api calls @@ -558,7 +567,14 @@ func CloneAllRepos(git git.Gitter, cloneTargets []scm.Repo) { // 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) + repoSlug = trimCollisionFilename(strings.Replace(repo.Path, "/", "_", -1)) + + // If a collision has another collision with trimmed name append a number + if _, ok := repoNameWithCollisions[repoSlug]; ok { + repoSlug = fmt.Sprintf("_%v_%v", strconv.Itoa(i), repoSlug) + } else { + repoNameWithCollisions[repoSlug] = true + } } repo.HostPath = filepath.Join(outputDirAbsolutePath, repoSlug) diff --git a/cmd/version.go b/cmd/version.go index b5dda2c..8aa33ef 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -6,7 +6,7 @@ import ( "github.com/spf13/cobra" ) -const ghorgVersion = "v1.8.7" +const ghorgVersion = "v1.8.8" var versionCmd = &cobra.Command{ Use: "version",