mirror of
https://github.com/psviderski/uncloud.git
synced 2026-08-26 11:03:34 +00:00
chore: inspecrt git state without an error if git utility not available
This commit is contained in:
@@ -8,7 +8,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GitState contains raw information about the Git repository state.
|
// GitState contains information about the Git repository state.
|
||||||
type GitState struct {
|
type GitState struct {
|
||||||
// IsDirty indicates whether there are uncommitted changes.
|
// IsDirty indicates whether there are uncommitted changes.
|
||||||
IsDirty bool
|
IsDirty bool
|
||||||
@@ -21,12 +21,17 @@ type GitState struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// InspectGitState inspects the Git repo state from the specified directory.
|
// InspectGitState inspects the Git repo state from the specified directory.
|
||||||
// If the directory is not a Git repository, returns GitState with IsRepo=false.
|
// If the directory is not a Git repository, or if git utility is not available,
|
||||||
|
// returns GitState with IsRepo=false and no error.
|
||||||
func InspectGitState(dir string) (GitState, error) {
|
func InspectGitState(dir string) (GitState, error) {
|
||||||
|
// Check if git command is available.
|
||||||
|
if _, err := exec.LookPath("git"); err != nil {
|
||||||
|
return GitState{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
state := GitState{
|
state := GitState{
|
||||||
IsRepo: isGitRepo(dir),
|
IsRepo: isGitRepo(dir),
|
||||||
}
|
}
|
||||||
|
|
||||||
if !state.IsRepo {
|
if !state.IsRepo {
|
||||||
return state, nil
|
return state, nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user