package gitcmd import ( "testing" ) func TestListCommitsByPath_ModifiedFile(t *testing.T) { f := newFixture(t) cs, err := f.repo.ListCommitsByPath("HEAD", "README.md", 0) if err != nil { t.Fatal(err) } if len(cs) != 2 { t.Fatalf("commits = %d, want 2: %+v", len(cs), cs) } if cs[0].ID != f.c3 || cs[1].ID != f.c1 { t.Errorf("order = %s, %s; want c3, c1", cs[0].ID, cs[1].ID) } } func TestListCommitsByPath_OnceAddedFile(t *testing.T) { f := newFixture(t) cs, err := f.repo.ListCommitsByPath("HEAD", "src/main.txt", 0) if err != nil { t.Fatal(err) } if len(cs) != 1 || cs[0].ID != f.c2 { t.Errorf("commits = %+v, want [c2]", cs) } } func TestListCommitsByPath_DeletedFileIncludesDelete(t *testing.T) { f := newFixture(t) cs, err := f.repo.ListCommitsByPath("HEAD", "deleted.txt", 0) if err != nil { t.Fatal(err) } if len(cs) != 2 { t.Fatalf("commits = %d, want 2: %+v", len(cs), cs) } if cs[0].ID != f.c5 || cs[1].ID != f.c2 { t.Errorf("order = %s, %s; want c5, c2", cs[0].ID, cs[1].ID) } } func TestListCommitsByPath_Limit(t *testing.T) { f := newFixture(t) cs, err := f.repo.ListCommitsByPath("HEAD", "README.md", 1) if err != nil { t.Fatal(err) } if len(cs) != 1 || cs[0].ID != f.c3 { t.Errorf("commits = %+v, want [c3] (limit 1, newest)", cs) } } func TestListCommitsByPath_MissingPath(t *testing.T) { f := newFixture(t) cs, err := f.repo.ListCommitsByPath("HEAD", "no/such/file.txt", 0) if err != nil { t.Fatalf("unexpected error: %v", err) } if len(cs) != 0 { t.Errorf("commits = %+v, want empty for missing path", cs) } }