(t *testing.T)
| 14 | ) |
| 15 | |
| 16 | func TestRunGitStatus(t *testing.T) { |
| 17 | tempDir, remoteDir := setupTestRepository(t) |
| 18 | |
| 19 | // Test case: Local commits |
| 20 | createCommit(t, tempDir, "test4.txt", "add a local file", "local commit") |
| 21 | |
| 22 | // Run GitFetch |
| 23 | require.NoError(t, GitFetch(t.Context(), tempDir, nil), "failed to fetch changes from remote repository") |
| 24 | // Run the RunGitStatus function again |
| 25 | status, err := RunGitStatus(tempDir, "", "origin", "") |
| 26 | require.NoError(t, err, "RunGitStatus failed after local commit") |
| 27 | |
| 28 | // Validate the updated status |
| 29 | require.Equal(t, int32(1), status.LocalCommits, "unexpected local commits after fourth commit") |
| 30 | require.Equal(t, int32(0), status.RemoteCommits, "unexpected remote commits") |
| 31 | |
| 32 | // Test case: Remote commits |
| 33 | createRemoteCommit(t, remoteDir, "test5.txt", "add a file in remote", "remote commit") |
| 34 | |
| 35 | // Fetch the latest changes from the remote repository before running RunGitStatus |
| 36 | require.NoError(t, GitFetch(t.Context(), tempDir, nil), "failed to fetch changes from remote repository") |
| 37 | |
| 38 | // Run the RunGitStatus function again |
| 39 | status, err = RunGitStatus(tempDir, "", "origin", "") |
| 40 | require.NoError(t, err, "RunGitStatus failed after local commit") |
| 41 | |
| 42 | // Validate the updated status |
| 43 | require.Equal(t, int32(1), status.LocalCommits, "unexpected local commits after fourth commit") |
| 44 | require.Equal(t, int32(1), status.RemoteCommits, "unexpected remote commits") |
| 45 | |
| 46 | // Test case: Untracked files |
| 47 | filePath := filepath.Join(tempDir, "untracked.txt") |
| 48 | err = os.WriteFile(filePath, []byte("untracked content"), 0644) |
| 49 | require.NoError(t, err, "failed to create untracked file") |
| 50 | |
| 51 | status, err = RunGitStatus(tempDir, "", "origin", "") |
| 52 | require.NoError(t, err, "RunGitStatus failed with untracked files") |
| 53 | require.True(t, status.LocalChanges, "expected local changes due to untracked files") |
| 54 | |
| 55 | // Test case: Staged but uncommitted changes |
| 56 | err = os.WriteFile(filePath, []byte("staged content"), 0644) |
| 57 | require.NoError(t, err, "failed to modify file for staging") |
| 58 | |
| 59 | cmd := exec.Command("git", "-C", tempDir, "add", "untracked.txt") |
| 60 | err = cmd.Run() |
| 61 | require.NoError(t, err, "failed to stage file") |
| 62 | |
| 63 | status, err = RunGitStatus(tempDir, "", "origin", "") |
| 64 | require.NoError(t, err, "RunGitStatus failed with staged changes") |
| 65 | require.True(t, status.LocalChanges, "expected local changes due to staged files") |
| 66 | |
| 67 | // Test case: Unstaged changes |
| 68 | err = os.WriteFile(filePath, []byte("unstaged content"), 0644) |
| 69 | require.NoError(t, err, "failed to modify file for unstaged changes") |
| 70 | |
| 71 | status, err = RunGitStatus(tempDir, "", "origin", "") |
| 72 | require.NoError(t, err, "RunGitStatus failed with unstaged changes") |
| 73 | require.True(t, status.LocalChanges, "expected local changes due to unstaged files") |
nothing calls this directly
no test coverage detected