fix: uc deploy should not crash in empty git repository (#275)

Co-authored-by: Anton Ovchinnikov <anton@tonyo.info>
This commit is contained in:
Copilot
2026-03-19 10:16:03 +10:00
committed by GitHub
co-authored by Anton Ovchinnikov
parent d2703cbc6b
commit 442f1d97a1
3 changed files with 23 additions and 3 deletions
+16
View File
@@ -46,6 +46,22 @@ func TestInspectGitState_NotARepo(t *testing.T) {
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) {
// Create a temporary git repo.
tmpDir := t.TempDir()