| 291 | } |
| 292 | |
| 293 | func TestRemoveDiscardsDirtyWork(t *testing.T) { |
| 294 | t.Parallel() |
| 295 | dir := bootstrapRepo(t) |
| 296 | |
| 297 | wt, err := Create(t.Context(), dir, "dirty", WithRoot(t.TempDir())) |
| 298 | require.NoError(t, err) |
| 299 | // Uncommitted change + untracked file + a new commit: removal must |
| 300 | // still succeed and wipe everything. |
| 301 | require.NoError(t, os.WriteFile(filepath.Join(wt.Dir, "a.txt"), []byte("changed"), 0o644)) |
| 302 | runGit(t, wt.Dir, "commit", "-am", "work") |
| 303 | require.NoError(t, os.WriteFile(filepath.Join(wt.Dir, "untracked.txt"), []byte("x"), 0o644)) |
| 304 | |
| 305 | require.NoError(t, wt.Remove(t.Context())) |
| 306 | assert.NoDirExists(t, wt.Dir) |
| 307 | } |
| 308 | |
| 309 | func bootstrapRepo(t *testing.T) string { |
| 310 | t.Helper() |