-
-
Notifications
You must be signed in to change notification settings - Fork 112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(DEV-2781): Notify Not Running in a Git Repo #990
base: main
Are you sure you want to change the base?
Changes from all commits
363f993
7247d20
11e0b71
14493bb
f6379fa
abfbd2d
8881b46
09c2ef7
51fb464
9df2042
43380e4
0553c0c
19d495e
10afc6f
bd1af2a
371c67e
22f3229
6668f6d
d0cc39b
2da0274
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
"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. | ||
|
@@ -523,6 +524,9 @@ | |
u.LogErrorAndExit(err) | ||
} | ||
|
||
// Check if we're in 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 | ||
u.PrintMessageInColor("atmos.yaml", c1) | ||
|
@@ -665,6 +669,36 @@ | |
return info | ||
} | ||
|
||
// isGitRepository checks if the current directory is within a git repository | ||
Check failure on line 672 in cmd/cmd_utils.go
|
||
func isGitRepository() bool { | ||
_, err := git.PlainOpenWithOptions(".", &git.PlainOpenOptions{ | ||
Check failure on line 674 in cmd/cmd_utils.go
|
||
DetectDotGit: true, | ||
}) | ||
if err != nil { | ||
if err != git.ErrRepositoryNotExists { | ||
Check failure on line 678 in cmd/cmd_utils.go
|
||
u.LogTrace(fmt.Sprintf("git check failed: %v", err)) | ||
Check failure on line 679 in cmd/cmd_utils.go
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use Semantic logging |
||
} | ||
return false | ||
} | ||
|
||
return true | ||
} | ||
|
||
// verifyInsideGitRepo checks if we're in a git repo | ||
Check failure on line 687 in cmd/cmd_utils.go
|
||
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 in a git repo | ||
if !isGitRepository() { | ||
u.LogWarning("You're not inside a git repository. Atmos feels lonely outside - bring it home!\n") | ||
Check failure on line 696 in cmd/cmd_utils.go
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please move to the semantic logging. |
||
return false | ||
} | ||
return true | ||
} | ||
|
||
func showErrorExampleFromMarkdown(cmd *cobra.Command, arg string) { | ||
commandPath := cmd.CommandPath() | ||
suggestions := []string{} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using errors.Is(err, git.ErrRepositoryNotExists) for error checking to correctly handle wrapped errors.
Copilot is powered by AI, so mistakes are possible. Review output carefully before use.