-
-
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
Open
milldr
wants to merge
19
commits into
main
Choose a base branch
from
DEV-2781/warning-when-not-git-repo
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+52
−0
Open
Changes from 14 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
363f993
Add check for git repository and required env vars
milldr 7247d20
Merge branch 'main' into DEV-2781/warning-when-not-git-repo
milldr 11e0b71
Add context and error handling to git repository check function
milldr 14493bb
Update git repository check using go-git package
milldr f6379fa
check for the root of the git project
milldr abfbd2d
Apply suggestions from code review
milldr 8881b46
Merge branch 'main' into DEV-2781/warning-when-not-git-repo
milldr 09c2ef7
[autofix.ci] apply automated fixes
autofix-ci[bot] 51fb464
corrected function name, return values
milldr 9df2042
revert unintended changes
milldr 43380e4
[autofix.ci] apply automated fixes
autofix-ci[bot] 0553c0c
Merge branch 'main' into DEV-2781/warning-when-not-git-repo
milldr 19d495e
revert git check for root
milldr 10afc6f
[autofix.ci] apply automated fixes
autofix-ci[bot] bd1af2a
Merge branch 'main' into DEV-2781/warning-when-not-git-repo
osterman 371c67e
merged main
milldr 22f3229
resolved merged conflicts
milldr 6668f6d
Merge branch 'main' into DEV-2781/warning-when-not-git-repo
osterman d0cc39b
Merge branch 'main' into DEV-2781/warning-when-not-git-repo
osterman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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,6 +459,9 @@ func printMessageForMissingAtmosConfig(atmosConfig schema.AtmosConfiguration) { | |
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) | ||
|
@@ -605,3 +609,33 @@ 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 { | ||
_, err := git.PlainOpenWithOptions(".", &git.PlainOpenOptions{ | ||
DetectDotGit: true, | ||
}) | ||
if err != nil { | ||
if err != git.ErrRepositoryNotExists { | ||
u.LogTrace(fmt.Sprintf("git check failed: %v", err)) | ||
} | ||
return false | ||
} | ||
|
||
return true | ||
} | ||
|
||
// 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 in a git repo | ||
if !isGitRepository() { | ||
u.LogWarning("You're not inside a git repository. Atmos feels lonely outside - bring it home!\n") | ||
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 | ||
} | ||
milldr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Use Semantic logging