-
-
Notifications
You must be signed in to change notification settings - Fork 110
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 9 commits
363f993
7247d20
11e0b71
14493bb
f6379fa
abfbd2d
8881b46
09c2ef7
51fb464
9df2042
43380e4
0553c0c
19d495e
10afc6f
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 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -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, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -458,6 +458,9 @@ func printMessageForMissingAtmosConfig(atmosConfig schema.AtmosConfiguration) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
u.LogErrorAndExit(atmosConfig, err) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// 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 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
u.PrintMessageInColor("atmos.yaml", c1) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -536,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)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -554,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()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -593,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 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -607,3 +608,40 @@ func getConfigAndStacksInfo(commandName string, cmd *cobra.Command, args []strin | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return info | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// isGitRepository checks if the current directory is the root of 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 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// 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)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return false | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return true | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// 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 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") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
milldr marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return false | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
milldr marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return true | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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. Fix LogWarning call argument. The LogWarning call has incorrect arguments. Remove the atmosConfig argument: - 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 at the root of a git repository. Atmos feels lonely outside - bring it home!\n") 📝 Committable suggestion
Suggested change
🧰 Tools🪛 GitHub Check: Build (macos-latest, macos)[failure] 642-642: 🪛 GitHub Check: Build (ubuntu-latest, linux)[failure] 642-642: |
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 |
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.
🛠️ Refactor suggestion
Consider using go-git for more robust Git repository detection.
The current implementation only checks for a
.git
directory in the current path. Using go-git would provide more reliable Git repository detection and support finding the repository root from subdirectories.Additionally, fix the LogTrace calls which have incorrect arguments:
📝 Committable suggestion
🧰 Tools
🪛 GitHub Check: Build (macos-latest, macos)
[failure] 617-617:
too many arguments in call to u.LogTrace
[failure] 625-625:
too many arguments in call to u.LogTrace
🪛 GitHub Check: Build (ubuntu-latest, linux)
[failure] 617-617:
too many arguments in call to u.LogTrace
[failure] 625-625:
too many arguments in call to u.LogTrace