Skip to content
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
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions cmd/cmd_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -607,3 +608,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 {
// Create a new repository instance pointing to the current directory
_, err := git.PlainOpenWithOptions(".", &git.PlainOpenOptions{
DetectDotGit: true,
})

if err != nil {
if err != git.ErrRepositoryNotExists {
u.LogTrace(atmosConfig, fmt.Sprintf("git check failed: %v", err))
}
return false
}

return true
}

// 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!")
}
}
4 changes: 4 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading