From 00b131e715257ec3bc79957fd4a7ea40d66ec6a6 Mon Sep 17 00:00:00 2001 From: gabrie30 Date: Sat, 7 Jan 2023 00:46:36 -0800 Subject: [PATCH] Fix gitlab folder structure when outputdir is specified (#274) --- examples/gitlab.md | 22 +- scm/gitlab.go | 4 +- scripts/local-gitlab/clone.sh | 269 +++++++++++++++++++++--- scripts/local-gitlab/get_credentials.sh | 3 +- scripts/local-gitlab/seed.sh | 26 ++- scripts/local-gitlab/start-ee.sh | 5 +- 6 files changed, 287 insertions(+), 42 deletions(-) diff --git a/examples/gitlab.md b/examples/gitlab.md index 06fc66b..07b873d 100644 --- a/examples/gitlab.md +++ b/examples/gitlab.md @@ -91,12 +91,29 @@ To view all additional flags see the [sample-conf.yaml](https://github.com/gabri └── project4 ``` -1. Clone **a specific subgroup** +1. Clone **a specific subgroup**, **WITHOUT preserving the directory structure** of subgroups ``` ghorg clone group3/subgroup1 --base-url=https:// --scm=gitlab --token=XXXXXX ``` + This would produce a directory structure like, where `projectX` is a project in a subgroup nested inside `subgroup1` + + ``` + /GHORG_ABSOLUTE_PATH_TO_CLONE_TO + └── group3 + └── subgroup1 + ├── projectX + ├── project3 + └── project4 + ``` + +1. Clone **a specific subgroup**, **preserving the directory structure** of subgroups + + ``` + ghorg clone group3/subgroup1 --base-url=https:// --scm=gitlab --token=XXXXXX --preserve-dir + ``` + This would produce a directory structure like ``` @@ -105,6 +122,9 @@ To view all additional flags see the [sample-conf.yaml](https://github.com/gabri └── subgroup1 ├── project3 └── project4 + └── subgroup2 + └── projectX + ``` #### Cloning a Specific Users Repos diff --git a/scm/gitlab.go b/scm/gitlab.go index fccc6bb..a1fc18e 100644 --- a/scm/gitlab.go +++ b/scm/gitlab.go @@ -305,7 +305,9 @@ func (c Gitlab) filter(group string, ps []*gitlab.Project) []Repo { // https://github.com/gabrie30/ghorg/issues/228 // https://github.com/gabrie30/ghorg/issues/267 if !gitLabAllGroups && !gitLabAllUsers { - path = strings.TrimPrefix(path, group) + if os.Getenv("GHORG_OUTPUT_DIR") == "" { + path = strings.TrimPrefix(path, group) + } } r.Path = path diff --git a/scripts/local-gitlab/clone.sh b/scripts/local-gitlab/clone.sh index 384f1ff..5102bac 100755 --- a/scripts/local-gitlab/clone.sh +++ b/scripts/local-gitlab/clone.sh @@ -4,6 +4,7 @@ set -ex TOKEN=${1:-'password'} GITLAB_URL=${2:-'http://gitlab.example.com'} +LOCAL_GITLAB_GHORG_DIR=${3:-"${HOME}/Desktop/ghorg"} export GHORG_INSECURE_GITLAB_CLIENT=true @@ -15,12 +16,12 @@ export GHORG_INSECURE_GITLAB_CLIENT=true ghorg clone all-groups --scm=gitlab --base-url="${GITLAB_URL}" --token="$TOKEN" --preserve-dir --output-dir=local-gitlab-v15-repos ghorg clone all-groups --scm=gitlab --base-url="${GITLAB_URL}" --token="$TOKEN" --preserve-dir --output-dir=local-gitlab-v15-repos -GOT=$( ghorg ls local-gitlab-v15-repos/group1 | grep -o 'local-gitlab-v15-repos/group1.*') +GOT=$( ghorg ls local-gitlab-v15-repos/local-gitlab-group1 | grep -o 'local-gitlab-v15-repos/local-gitlab-group1.*') WANT=$(cat <> /etc/hosts @@ -15,7 +16,7 @@ fi docker rm gitlab --force --volumes -rm -rf $HOME/Desktop/ghorg/local-gitlab-v15-* +rm -rf $HOME/Desktop/ghorg/local-gitlab-* echo "" echo "To follow gitlab container logs use the following command in a new window" @@ -23,7 +24,7 @@ echo "$ docker logs -f gitlab" echo "" ./scripts/local-gitlab/run-ee.sh "${GITLAB_IMAGE_TAG}" "${GITLAB_HOME}" "${GITLAB_HOST}" "${PERSIST_GITLAB_LOCALLY}" -./scripts/local-gitlab/get_credentials.sh "${GITLAB_URL}" +./scripts/local-gitlab/get_credentials.sh "${GITLAB_URL}" "${LOCAL_GITLAB_GHORG_DIR}" if [ "${STOP_GITLAB_WHEN_FINISHED}" == "true" ];then docker rm gitlab --force --volumes