mirror of
https://github.com/psviderski/uncloud.git
synced 2026-08-26 11:03:34 +00:00
fix: uc deploy should not crash in empty git repository (#275)
Co-authored-by: Anton Ovchinnikov <anton@tonyo.info>
This commit is contained in:
co-authored by
Anton Ovchinnikov
parent
d2703cbc6b
commit
442f1d97a1
@@ -8,7 +8,9 @@
|
|||||||
*.so
|
*.so
|
||||||
*.dylib
|
*.dylib
|
||||||
/uncloud
|
/uncloud
|
||||||
|
/uncloud-*
|
||||||
/uncloudd
|
/uncloudd
|
||||||
|
/uncloudd-*
|
||||||
|
|
||||||
# OS X
|
# OS X
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
|||||||
@@ -36,10 +36,12 @@ func InspectGitState(dir string) (GitState, error) {
|
|||||||
return state, nil
|
return state, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the current commit SHA.
|
// Get the current commit SHA. An initialised but empty repo has no HEAD yet,
|
||||||
sha, err := gitCommand(dir, "rev-parse", "HEAD")
|
// so treat it as a non-repo so callers can fall back to non-git logic.
|
||||||
|
sha, err := gitCommand(dir, "rev-parse", "--verify", "HEAD")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return state, fmt.Errorf("get current commit SHA: %w", err)
|
state.IsRepo = false
|
||||||
|
return state, nil
|
||||||
}
|
}
|
||||||
state.SHA = strings.TrimSpace(sha)
|
state.SHA = strings.TrimSpace(sha)
|
||||||
|
|
||||||
|
|||||||
@@ -46,6 +46,22 @@ func TestInspectGitState_NotARepo(t *testing.T) {
|
|||||||
assert.False(t, state.IsDirty)
|
assert.False(t, state.IsDirty)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestInspectGitState_EmptyRepo(t *testing.T) {
|
||||||
|
// Create a temporary git repo with no commits.
|
||||||
|
tmpDir := t.TempDir()
|
||||||
|
initGitRepo(t, tmpDir)
|
||||||
|
|
||||||
|
state, err := InspectGitState(tmpDir)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
// An empty repo should be treated as a non-repo so that callers fall back to non-git logic.
|
||||||
|
assert.False(t, state.IsRepo)
|
||||||
|
assert.Empty(t, state.SHA)
|
||||||
|
assert.Empty(t, state.ShortSHA(7))
|
||||||
|
assert.True(t, state.Date.IsZero())
|
||||||
|
assert.False(t, state.IsDirty)
|
||||||
|
}
|
||||||
|
|
||||||
func TestInspectGitState_CleanRepo(t *testing.T) {
|
func TestInspectGitState_CleanRepo(t *testing.T) {
|
||||||
// Create a temporary git repo.
|
// Create a temporary git repo.
|
||||||
tmpDir := t.TempDir()
|
tmpDir := t.TempDir()
|
||||||
|
|||||||
Reference in New Issue
Block a user