From bf0dc6dcab67be0f14949dcf84babe58e5abe773 Mon Sep 17 00:00:00 2001 From: Pedro Enrique Date: Mon, 30 Jun 2025 16:16:05 +0200 Subject: [PATCH 1/2] =?UTF-8?q?[GITHUB-338]=20Do=20not=20create=20a=20git?= =?UTF-8?q?=20repo=20if=20we=E2=80=99re=20already=20in=20a=20git=20repo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/project.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/cmd/project.go b/cmd/project.go index 99e52473..aec81a1e 100644 --- a/cmd/project.go +++ b/cmd/project.go @@ -633,8 +633,22 @@ Examples: } logger.Debug("git info: %+v", gitInfo) + // Only initialize a new git repo if there is no parent git repo + // (i.e., if the closest .git is the projectDir itself, not a parent) if !gitInfo.IsRepo { projectGitFlow(ctx, provider, tmplContext, githubAction) + } else { + // Check if the found git repo is in a parent directory + // If so, do NOT run projectGitFlow (do not create a sub-repo) + // If the found .git is in projectDir, it's safe to run projectGitFlow + parentGitInfo, _ := deployer.GetGitInfo(logger, projectDir) + if parentGitInfo != nil && parentGitInfo.IsRepo { + // There is a .git in projectDir, so it's safe to run projectGitFlow + projectGitFlow(ctx, provider, tmplContext, githubAction) + } else { + // There is a parent git repo, do not create a sub-repo + logger.Info("Project is inside an existing git repository; not creating a new git repo.") + } } if format == "json" { From dfe6e7d5e752abb692d116c6ec23fbeef2e1f62a Mon Sep 17 00:00:00 2001 From: Pedro Enrique Date: Mon, 30 Jun 2025 22:44:29 +0200 Subject: [PATCH 2/2] Coder Rabbit comments --- cmd/project.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/cmd/project.go b/cmd/project.go index aec81a1e..79bafe63 100644 --- a/cmd/project.go +++ b/cmd/project.go @@ -638,15 +638,17 @@ Examples: if !gitInfo.IsRepo { projectGitFlow(ctx, provider, tmplContext, githubAction) } else { - // Check if the found git repo is in a parent directory - // If so, do NOT run projectGitFlow (do not create a sub-repo) - // If the found .git is in projectDir, it's safe to run projectGitFlow - parentGitInfo, _ := deployer.GetGitInfo(logger, projectDir) - if parentGitInfo != nil && parentGitInfo.IsRepo { - // There is a .git in projectDir, so it's safe to run projectGitFlow + // Check if there's a .git directory directly in the project directory + // If so, it's safe to run projectGitFlow; otherwise, we're in a parent git repo + projectDirGitInfo, err := deployer.GetGitInfo(logger, projectDir) + if err != nil { + logger.Debug("failed to get git info for project directory: %s", err) + } + if projectDirGitInfo != nil && projectDirGitInfo.IsRepo { + // There is a .git directly in projectDir, so it's safe to run projectGitFlow projectGitFlow(ctx, provider, tmplContext, githubAction) } else { - // There is a parent git repo, do not create a sub-repo + // We're inside a parent git repository, do not create a nested repo logger.Info("Project is inside an existing git repository; not creating a new git repo.") } }