From 363f99312a73429e7f685e71244facb2e4c37a99 Mon Sep 17 00:00:00 2001 From: milldr Date: Thu, 30 Jan 2025 13:41:26 -0500 Subject: [PATCH 01/11] Add check for git repository and required env vars --- cmd/cmd_utils.go | 22 ++++++++++++++++++++++ cmd/root.go | 4 ++++ 2 files changed, 26 insertions(+) diff --git a/cmd/cmd_utils.go b/cmd/cmd_utils.go index 79d3f242a..b5ebfd81e 100644 --- a/cmd/cmd_utils.go +++ b/cmd/cmd_utils.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" "os" + "os/exec" "path/filepath" "strings" "time" @@ -607,3 +608,24 @@ func getConfigAndStacksInfo(commandName string, cmd *cobra.Command, args []strin } return info } + +// isGitRepository checks if the current directory is within a git repository +func isGitRepository() bool { + cmd := exec.Command("git", "rev-parse", "--is-inside-work-tree") + cmd.Stderr = nil + err := cmd.Run() + return err == nil +} + +// checkGitAndEnvVars checks if we're in a git repo and if required env vars are set +func checkGitAndEnvVars() { + // Skip check if either env var is set + if os.Getenv("ATMOS_BASE_PATH") != "" || os.Getenv("ATMOS_CLI_CONFIG_PATH") != "" { + return + } + + // Check if we're in a git repo + if !isGitRepository() { + u.LogWarning(atmosConfig, "You're not inside a git repository. Atmos feels lonely outside - bring it home!") + } +} diff --git a/cmd/root.go b/cmd/root.go index 91e34582f..8e960f1d0 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -109,6 +109,10 @@ func Execute() error { u.LogErrorAndExit(schema.AtmosConfiguration{}, initErr) } } + + // Check if we're in a git repo and report a warning if not + checkGitAndEnvVars() + var err error // If CLI configuration was found, process its custom commands and command aliases if initErr == nil { From 11e0b71b61c421824c92256e2b23eb1d7af895c6 Mon Sep 17 00:00:00 2001 From: milldr Date: Thu, 30 Jan 2025 14:02:13 -0500 Subject: [PATCH 02/11] Add context and error handling to git repository check function --- cmd/cmd_utils.go | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/cmd/cmd_utils.go b/cmd/cmd_utils.go index b5ebfd81e..aaf166c43 100644 --- a/cmd/cmd_utils.go +++ b/cmd/cmd_utils.go @@ -1,6 +1,8 @@ package cmd import ( + "bytes" + "context" "encoding/json" "errors" "fmt" @@ -611,10 +613,37 @@ func getConfigAndStacksInfo(commandName string, cmd *cobra.Command, args []strin // isGitRepository checks if the current directory is within a git repository func isGitRepository() bool { - cmd := exec.Command("git", "rev-parse", "--is-inside-work-tree") - cmd.Stderr = nil + // Create command with timeout context + ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second) + defer cancel() + + cmd := exec.CommandContext(ctx, "git", "rev-parse", "--is-inside-work-tree") + + // Capture stderr for debugging + var stderr bytes.Buffer + cmd.Stderr = &stderr + + // Run the command err := cmd.Run() - return err == nil + + // Check for timeout + if ctx.Err() == context.DeadlineExceeded { + u.LogTrace(atmosConfig, "git check timed out after 3 seconds") + return false + } + + // Check if git is not installed + if errors.Is(err, exec.ErrNotFound) { + u.LogTrace(atmosConfig, "git is not installed") + return false + } + + if err != nil { + u.LogTrace(atmosConfig, fmt.Sprintf("git check failed: %v (stderr: %s)", err, stderr.String())) + return false + } + + return true } // checkGitAndEnvVars checks if we're in a git repo and if required env vars are set From 14493bb8841ce185d7806b8a161b5ea2d67131fb Mon Sep 17 00:00:00 2001 From: milldr Date: Thu, 30 Jan 2025 14:31:21 -0500 Subject: [PATCH 03/11] Update git repository check using go-git package --- cmd/cmd_utils.go | 36 ++++++++---------------------------- 1 file changed, 8 insertions(+), 28 deletions(-) diff --git a/cmd/cmd_utils.go b/cmd/cmd_utils.go index aaf166c43..c36fec5a9 100644 --- a/cmd/cmd_utils.go +++ b/cmd/cmd_utils.go @@ -1,13 +1,10 @@ package cmd import ( - "bytes" - "context" "encoding/json" "errors" "fmt" "os" - "os/exec" "path/filepath" "strings" "time" @@ -22,6 +19,7 @@ import ( "github.com/cloudposse/atmos/pkg/ui/theme" u "github.com/cloudposse/atmos/pkg/utils" "github.com/cloudposse/atmos/pkg/version" + "github.com/go-git/go-git/v5" ) // ValidateConfig holds configuration options for Atmos validation. @@ -613,33 +611,15 @@ func getConfigAndStacksInfo(commandName string, cmd *cobra.Command, args []strin // isGitRepository checks if the current directory is within a git repository func isGitRepository() bool { - // Create command with timeout context - ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second) - defer cancel() - - cmd := exec.CommandContext(ctx, "git", "rev-parse", "--is-inside-work-tree") - - // Capture stderr for debugging - var stderr bytes.Buffer - cmd.Stderr = &stderr - - // Run the command - err := cmd.Run() - - // Check for timeout - if ctx.Err() == context.DeadlineExceeded { - u.LogTrace(atmosConfig, "git check timed out after 3 seconds") - return false - } - - // Check if git is not installed - if errors.Is(err, exec.ErrNotFound) { - u.LogTrace(atmosConfig, "git is not installed") - return false - } + // Create a new repository instance pointing to the current directory + _, err := git.PlainOpenWithOptions(".", &git.PlainOpenOptions{ + DetectDotGit: true, + }) if err != nil { - u.LogTrace(atmosConfig, fmt.Sprintf("git check failed: %v (stderr: %s)", err, stderr.String())) + if err != git.ErrRepositoryNotExists { + u.LogTrace(atmosConfig, fmt.Sprintf("git check failed: %v", err)) + } return false } From f6379fa1baca20937702e2351378660a90c87219 Mon Sep 17 00:00:00 2001 From: milldr Date: Thu, 30 Jan 2025 16:46:21 -0500 Subject: [PATCH 04/11] check for the root of the git project --- cmd/cmd_utils.go | 26 +++++++++++++--------- cmd/root.go | 3 --- tests/test-cases/empty-dir.yaml | 18 +++++++++++++++ tests/test-cases/log-level-validation.yaml | 2 +- 4 files changed, 35 insertions(+), 14 deletions(-) diff --git a/cmd/cmd_utils.go b/cmd/cmd_utils.go index c36fec5a9..fe67ddf33 100644 --- a/cmd/cmd_utils.go +++ b/cmd/cmd_utils.go @@ -19,7 +19,6 @@ import ( "github.com/cloudposse/atmos/pkg/ui/theme" u "github.com/cloudposse/atmos/pkg/utils" "github.com/cloudposse/atmos/pkg/version" - "github.com/go-git/go-git/v5" ) // ValidateConfig holds configuration options for Atmos validation. @@ -459,6 +458,9 @@ func printMessageForMissingAtmosConfig(atmosConfig schema.AtmosConfiguration) { u.LogErrorAndExit(atmosConfig, err) } + // Check if we're in a git repo and report a warning if not + checkGitAndEnvVars() + if atmosConfig.Default { // If Atmos did not find an `atmos.yaml` config file and is using the default config u.PrintMessageInColor("atmos.yaml", c1) @@ -609,15 +611,19 @@ func getConfigAndStacksInfo(commandName string, cmd *cobra.Command, args []strin return info } -// isGitRepository checks if the current directory is within a git repository +// isGitRepository checks if the current directory is the root of a git repository func isGitRepository() bool { - // Create a new repository instance pointing to the current directory - _, err := git.PlainOpenWithOptions(".", &git.PlainOpenOptions{ - DetectDotGit: true, - }) + // Get current working directory + currentDir, err := os.Getwd() + if err != nil { + u.LogTrace(atmosConfig, fmt.Sprintf("failed to get current directory: %v", err)) + return false + } + // Check if .git directory exists directly in the current directory + _, err = os.Stat(filepath.Join(currentDir, ".git")) if err != nil { - if err != git.ErrRepositoryNotExists { + if !os.IsNotExist(err) { u.LogTrace(atmosConfig, fmt.Sprintf("git check failed: %v", err)) } return false @@ -626,15 +632,15 @@ func isGitRepository() bool { return true } -// checkGitAndEnvVars checks if we're in a git repo and if required env vars are set +// checkGitAndEnvVars checks if we're at the root of a git repo and if required env vars are set func checkGitAndEnvVars() { // Skip check if either env var is set if os.Getenv("ATMOS_BASE_PATH") != "" || os.Getenv("ATMOS_CLI_CONFIG_PATH") != "" { return } - // Check if we're in a git repo + // Check if we're at the root of a git repo if !isGitRepository() { - u.LogWarning(atmosConfig, "You're not inside a git repository. Atmos feels lonely outside - bring it home!") + u.LogWarning(atmosConfig, "You're not at the root of a git repository. Atmos feels lonely outside - bring it home!\n") } } diff --git a/cmd/root.go b/cmd/root.go index 8e960f1d0..f28530a73 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -110,9 +110,6 @@ func Execute() error { } } - // Check if we're in a git repo and report a warning if not - checkGitAndEnvVars() - var err error // If CLI configuration was found, process its custom commands and command aliases if initErr == nil { diff --git a/tests/test-cases/empty-dir.yaml b/tests/test-cases/empty-dir.yaml index 29c051d51..9fae74195 100644 --- a/tests/test-cases/empty-dir.yaml +++ b/tests/test-cases/empty-dir.yaml @@ -46,3 +46,21 @@ tests: stderr: - "^$" exit_code: 0 + + - name: run atmos outside git repo + enabled: true + snapshot: true + description: "Test checkGitAndEnvVars function outside of a git repo with ATMOS_LOGS_LEVEL=Warn" + workdir: "fixtures/scenarios/empty-dir" + command: "atmos" + args: + - version + env: + ATMOS_LOGS_LEVEL: Warning + expect: + diff: [] + stdout: + - "You're not at the root of a git repository. Atmos feels lonely outside - bring it home!" + stderr: + - "^$" + exit_code: 0 \ No newline at end of file diff --git a/tests/test-cases/log-level-validation.yaml b/tests/test-cases/log-level-validation.yaml index 18fd16ef7..815167112 100644 --- a/tests/test-cases/log-level-validation.yaml +++ b/tests/test-cases/log-level-validation.yaml @@ -90,4 +90,4 @@ tests: - '^\n👽 Atmos (\d+\.\d+\.\d+|test) on [a-z]+/[a-z0-9_]+\n\n' stderr: - "^$" - exit_code: 0 + exit_code: 0 \ No newline at end of file From abfbd2d18192baf916d326854975aefec9a54601 Mon Sep 17 00:00:00 2001 From: Dan Miller Date: Thu, 30 Jan 2025 22:10:45 -0500 Subject: [PATCH 05/11] Apply suggestions from code review Co-authored-by: Erik Osterman (CEO @ Cloud Posse) --- cmd/cmd_utils.go | 8 +++++--- tests/test-cases/empty-dir.yaml | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/cmd/cmd_utils.go b/cmd/cmd_utils.go index fe67ddf33..fac80ec31 100644 --- a/cmd/cmd_utils.go +++ b/cmd/cmd_utils.go @@ -632,15 +632,17 @@ func isGitRepository() bool { return true } -// checkGitAndEnvVars checks if we're at the root of a git repo and if required env vars are set -func checkGitAndEnvVars() { +// verifyInsideGitRepo checks if we're at the root of a git repo, if required env vars are not set +func verifyInsideGitRepo() bool { // Skip check if either env var is set if os.Getenv("ATMOS_BASE_PATH") != "" || os.Getenv("ATMOS_CLI_CONFIG_PATH") != "" { - return + return nil } // Check if we're at the root of a git repo if !isGitRepository() { u.LogWarning(atmosConfig, "You're not at the root of a git repository. Atmos feels lonely outside - bring it home!\n") + return false + return true } } diff --git a/tests/test-cases/empty-dir.yaml b/tests/test-cases/empty-dir.yaml index 9fae74195..d68ad8d0f 100644 --- a/tests/test-cases/empty-dir.yaml +++ b/tests/test-cases/empty-dir.yaml @@ -47,10 +47,10 @@ tests: - "^$" exit_code: 0 - - name: run atmos outside git repo + - name: atmos warns if not in git repo enabled: true snapshot: true - description: "Test checkGitAndEnvVars function outside of a git repo with ATMOS_LOGS_LEVEL=Warn" + description: "Test that atmos warns if not run inside of a git repo" workdir: "fixtures/scenarios/empty-dir" command: "atmos" args: From 09c2ef78305962fd8a730c3439af4bb5512013c7 Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Fri, 31 Jan 2025 14:36:13 +0000 Subject: [PATCH 06/11] [autofix.ci] apply automated fixes --- cmd/cmd_utils.go | 16 +++++++--------- cmd/root.go | 1 - 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/cmd/cmd_utils.go b/cmd/cmd_utils.go index fac80ec31..8a2fc6d4c 100644 --- a/cmd/cmd_utils.go +++ b/cmd/cmd_utils.go @@ -62,7 +62,7 @@ func processCustomCommands( if _, exist := existingTopLevelCommands[commandConfig.Name]; exist && topLevel { command = existingTopLevelCommands[commandConfig.Name] } else { - var customCommand = &cobra.Command{ + customCommand := &cobra.Command{ Use: commandConfig.Name, Short: commandConfig.Description, Long: commandConfig.Description, @@ -132,7 +132,7 @@ func processCommandAliases( aliasCmd := strings.TrimSpace(v) aliasFor := fmt.Sprintf("alias for '%s'", aliasCmd) - var aliasCommand = &cobra.Command{ + aliasCommand := &cobra.Command{ Use: alias, Short: aliasFor, Long: aliasFor, @@ -170,7 +170,7 @@ func preCustomCommand( ) { var sb strings.Builder - //checking for zero arguments in config + // checking for zero arguments in config if len(commandConfig.Arguments) == 0 { if len(commandConfig.Steps) > 0 { // do nothing here; let the code proceed @@ -193,7 +193,7 @@ func preCustomCommand( } } - //Check on many arguments required and have no default value + // Check on many arguments required and have no default value requiredNoDefaultCount := 0 for _, arg := range commandConfig.Arguments { if arg.Required && arg.Default == "" { @@ -310,7 +310,7 @@ func executeCustomCommand( } // Prepare template data - var data = map[string]any{ + data := map[string]any{ "Arguments": argumentsData, "Flags": flagsData, } @@ -539,7 +539,6 @@ func CheckForAtmosUpdateAndPrintMessage(atmosConfig schema.AtmosConfiguration) { cacheCfg.LastChecked = time.Now().Unix() if saveErr := cfg.SaveCache(cacheCfg); saveErr != nil { u.LogWarning(atmosConfig, fmt.Sprintf("Unable to save cache: %s", saveErr)) - } } @@ -557,7 +556,6 @@ func handleHelpRequest(cmd *cobra.Command, args []string) { } func showUsageAndExit(cmd *cobra.Command, args []string) { - var suggestions []string unknownCommand := fmt.Sprintf("Error: Unknown command: %q\n\n", cmd.CommandPath()) @@ -596,7 +594,7 @@ func getConfigAndStacksInfo(commandName string, cmd *cobra.Command, args []strin checkAtmosConfig() var argsAfterDoubleDash []string - var finalArgs = args + finalArgs := args doubleDashIndex := lo.IndexOf(args, "--") if doubleDashIndex > 0 { @@ -643,6 +641,6 @@ func verifyInsideGitRepo() bool { if !isGitRepository() { u.LogWarning(atmosConfig, "You're not at the root of a git repository. Atmos feels lonely outside - bring it home!\n") return false - return true + return true } } diff --git a/cmd/root.go b/cmd/root.go index f28530a73..086a8d597 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -183,7 +183,6 @@ func initCobraConfig() { return nil }) RootCmd.SetHelpFunc(func(command *cobra.Command, args []string) { - if !(Contains(os.Args, "help") || Contains(os.Args, "--help") || Contains(os.Args, "-h")) { arguments := os.Args[len(strings.Split(command.CommandPath(), " ")):] if len(command.Flags().Args()) > 0 { From 51fb464359dcc6d3bff2751d5500f4eacf0f33d3 Mon Sep 17 00:00:00 2001 From: milldr Date: Fri, 31 Jan 2025 09:39:02 -0500 Subject: [PATCH 07/11] corrected function name, return values --- cmd/cmd_utils.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/cmd/cmd_utils.go b/cmd/cmd_utils.go index 8a2fc6d4c..16b4323b2 100644 --- a/cmd/cmd_utils.go +++ b/cmd/cmd_utils.go @@ -458,8 +458,8 @@ func printMessageForMissingAtmosConfig(atmosConfig schema.AtmosConfiguration) { u.LogErrorAndExit(atmosConfig, err) } - // Check if we're in a git repo and report a warning if not - checkGitAndEnvVars() + // Check if we're at the root of a git repo. Warn if not. + verifyInsideGitRepo() if atmosConfig.Default { // If Atmos did not find an `atmos.yaml` config file and is using the default config @@ -634,13 +634,14 @@ func isGitRepository() bool { func verifyInsideGitRepo() bool { // Skip check if either env var is set if os.Getenv("ATMOS_BASE_PATH") != "" || os.Getenv("ATMOS_CLI_CONFIG_PATH") != "" { - return nil + return true } // Check if we're at the root of a git repo if !isGitRepository() { u.LogWarning(atmosConfig, "You're not at the root of a git repository. Atmos feels lonely outside - bring it home!\n") return false - return true } + + return true } From 9df204234785c679e04618896b71b46579211be5 Mon Sep 17 00:00:00 2001 From: milldr Date: Fri, 31 Jan 2025 09:51:38 -0500 Subject: [PATCH 08/11] revert unintended changes --- cmd/cmd_utils.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cmd/cmd_utils.go b/cmd/cmd_utils.go index 16b4323b2..5b3545ed8 100644 --- a/cmd/cmd_utils.go +++ b/cmd/cmd_utils.go @@ -62,7 +62,7 @@ func processCustomCommands( if _, exist := existingTopLevelCommands[commandConfig.Name]; exist && topLevel { command = existingTopLevelCommands[commandConfig.Name] } else { - customCommand := &cobra.Command{ + var customCommand = &cobra.Command{ Use: commandConfig.Name, Short: commandConfig.Description, Long: commandConfig.Description, @@ -132,7 +132,7 @@ func processCommandAliases( aliasCmd := strings.TrimSpace(v) aliasFor := fmt.Sprintf("alias for '%s'", aliasCmd) - aliasCommand := &cobra.Command{ + var aliasCommand = &cobra.Command{ Use: alias, Short: aliasFor, Long: aliasFor, @@ -310,7 +310,7 @@ func executeCustomCommand( } // Prepare template data - data := map[string]any{ + var data = map[string]any{ "Arguments": argumentsData, "Flags": flagsData, } @@ -594,7 +594,7 @@ func getConfigAndStacksInfo(commandName string, cmd *cobra.Command, args []strin checkAtmosConfig() var argsAfterDoubleDash []string - finalArgs := args + var finalArgs = args doubleDashIndex := lo.IndexOf(args, "--") if doubleDashIndex > 0 { From 43380e4a50e2316e87214835a6de14e94109a518 Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Fri, 31 Jan 2025 14:52:22 +0000 Subject: [PATCH 09/11] [autofix.ci] apply automated fixes --- cmd/cmd_utils.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cmd/cmd_utils.go b/cmd/cmd_utils.go index 5b3545ed8..16b4323b2 100644 --- a/cmd/cmd_utils.go +++ b/cmd/cmd_utils.go @@ -62,7 +62,7 @@ func processCustomCommands( if _, exist := existingTopLevelCommands[commandConfig.Name]; exist && topLevel { command = existingTopLevelCommands[commandConfig.Name] } else { - var customCommand = &cobra.Command{ + customCommand := &cobra.Command{ Use: commandConfig.Name, Short: commandConfig.Description, Long: commandConfig.Description, @@ -132,7 +132,7 @@ func processCommandAliases( aliasCmd := strings.TrimSpace(v) aliasFor := fmt.Sprintf("alias for '%s'", aliasCmd) - var aliasCommand = &cobra.Command{ + aliasCommand := &cobra.Command{ Use: alias, Short: aliasFor, Long: aliasFor, @@ -310,7 +310,7 @@ func executeCustomCommand( } // Prepare template data - var data = map[string]any{ + data := map[string]any{ "Arguments": argumentsData, "Flags": flagsData, } @@ -594,7 +594,7 @@ func getConfigAndStacksInfo(commandName string, cmd *cobra.Command, args []strin checkAtmosConfig() var argsAfterDoubleDash []string - var finalArgs = args + finalArgs := args doubleDashIndex := lo.IndexOf(args, "--") if doubleDashIndex > 0 { From 19d495e48fc97f3859ab02a137c65f8936b2593b Mon Sep 17 00:00:00 2001 From: milldr Date: Fri, 31 Jan 2025 18:56:02 -0500 Subject: [PATCH 10/11] revert git check for root --- cmd/cmd_utils.go | 27 +++++++++++---------------- tests/test-cases/empty-dir.yaml | 2 +- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/cmd/cmd_utils.go b/cmd/cmd_utils.go index 924c69045..17ca7c23e 100644 --- a/cmd/cmd_utils.go +++ b/cmd/cmd_utils.go @@ -19,6 +19,7 @@ import ( "github.com/cloudposse/atmos/pkg/ui/theme" u "github.com/cloudposse/atmos/pkg/utils" "github.com/cloudposse/atmos/pkg/version" + "github.com/go-git/go-git/v5" ) // ValidateConfig holds configuration options for Atmos validation. @@ -458,7 +459,7 @@ func printMessageForMissingAtmosConfig(atmosConfig schema.AtmosConfiguration) { u.LogErrorAndExit(err) } - // Check if we're at the root of a git repo. Warn if not. + // Check if we're in a git repo. Warn if not. verifyInsideGitRepo() if atmosConfig.Default { @@ -609,20 +610,15 @@ func getConfigAndStacksInfo(commandName string, cmd *cobra.Command, args []strin return info } -// isGitRepository checks if the current directory is the root of a git repository +// isGitRepository checks if the current directory is within a git repository func isGitRepository() bool { - // Get current working directory - currentDir, err := os.Getwd() - if err != nil { - u.LogTrace(atmosConfig, fmt.Sprintf("failed to get current directory: %v", err)) - return false - } + _, err := git.PlainOpenWithOptions(".", &git.PlainOpenOptions{ + DetectDotGit: true, + }) - // Check if .git directory exists directly in the current directory - _, err = os.Stat(filepath.Join(currentDir, ".git")) if err != nil { - if !os.IsNotExist(err) { - u.LogTrace(atmosConfig, fmt.Sprintf("git check failed: %v", err)) + if err != git.ErrRepositoryNotExists { + u.LogTrace(fmt.Sprintf("git check failed: %v", err)) } return false } @@ -630,18 +626,17 @@ func isGitRepository() bool { return true } -// verifyInsideGitRepo checks if we're at the root of a git repo, if required env vars are not set +// verifyInsideGitRepo checks if we're in a git repo func verifyInsideGitRepo() bool { // Skip check if either env var is set if os.Getenv("ATMOS_BASE_PATH") != "" || os.Getenv("ATMOS_CLI_CONFIG_PATH") != "" { return true } - // Check if we're at the root of a git repo + // Check if we're in a git repo if !isGitRepository() { - u.LogWarning(atmosConfig, "You're not at the root of a git repository. Atmos feels lonely outside - bring it home!\n") + u.LogWarning("You're not inside a git repository. Atmos feels lonely outside - bring it home!\n") return false } - return true } diff --git a/tests/test-cases/empty-dir.yaml b/tests/test-cases/empty-dir.yaml index 8112fe79d..a18fafaa4 100644 --- a/tests/test-cases/empty-dir.yaml +++ b/tests/test-cases/empty-dir.yaml @@ -62,7 +62,7 @@ tests: expect: diff: [] stdout: - - "You're not at the root of a git repository. Atmos feels lonely outside - bring it home!" + - "You're not inside a git repository. Atmos feels lonely outside - bring it home!" stderr: - "^$" exit_code: 0 \ No newline at end of file From 10afc6f74cdb552897c2a0f7e3826f2a8b74ae53 Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Fri, 31 Jan 2025 23:56:43 +0000 Subject: [PATCH 11/11] [autofix.ci] apply automated fixes --- cmd/cmd_utils.go | 1 - 1 file changed, 1 deletion(-) diff --git a/cmd/cmd_utils.go b/cmd/cmd_utils.go index 17ca7c23e..d209ae62a 100644 --- a/cmd/cmd_utils.go +++ b/cmd/cmd_utils.go @@ -615,7 +615,6 @@ func isGitRepository() bool { _, err := git.PlainOpenWithOptions(".", &git.PlainOpenOptions{ DetectDotGit: true, }) - if err != nil { if err != git.ErrRepositoryNotExists { u.LogTrace(fmt.Sprintf("git check failed: %v", err))