Skip to content

Commit

Permalink
modify tests
Browse files Browse the repository at this point in the history
  • Loading branch information
purpleclay committed Dec 21, 2024
1 parent 6a98754 commit 4af927b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
13 changes: 8 additions & 5 deletions gittest/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const (
ReadmeContent = "# Gitz Test Repository\n\n" + FileContent

// an internal template for pushing changes back to a remote origin
gitPushTemplate = "git push origin %s"
gitPushTemplate = "git push -u origin %s"
)

// RepositoryOption provides a utility for setting repository options during
Expand Down Expand Up @@ -764,17 +764,20 @@ func Log(t *testing.T) []LogEntry {
return ParseLog(log)
}

// LogFrom ...
// LogFor returns the log history of a repository (working directory)
// at the given paths. Useful if you need to understand the history
// behind any number of files or directories. This will ignore any
// empty commits
//
// git log -- '<path>' '<path>'
func LogFrom(t *testing.T, paths ...string) []LogEntry {
// git log --pretty='format:> %%H %%d %%s%%+b%%-N' -- '<path>' '<path>'
func LogFor(t *testing.T, paths ...string) []LogEntry {
t.Helper()
var quotedPaths []string
for _, path := range paths {
quotedPaths = append(quotedPaths, fmt.Sprintf("'%s'", path))
}

log := MustExec(t, fmt.Sprintf("git log -- %s", strings.Join(quotedPaths, " ")))
log := MustExec(t, fmt.Sprintf("git log --pretty='format:> %%H %%d %%s%%+b%%-N' -- %s", strings.Join(quotedPaths, " ")))
return ParseLog(log)
}

Expand Down
13 changes: 7 additions & 6 deletions gittest/repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,13 +467,14 @@ func TestLogBetween(t *testing.T) {
assert.Equal(t, "chore: tagged 0.2.0", diffLog[0].Message)
}

func TestLogFrom(t *testing.T) {
// log := `(main, origin/main) chore: this should also appear in log
// chore: this should appear in log`
gittest.InitRepository(t)
func TestLogFor(t *testing.T) {
log := `(main) chore: this should also appear in log
chore: this should appear in log`
gittest.InitRepository(t, gittest.WithLog(log))

localLog := gittest.LogFrom(t)
require.Len(t, localLog, 3)
localLog := gittest.LogFor(t, ".")
require.Len(t, localLog, 1)
assert.Equal(t, gittest.InitialCommit, localLog[0].Message)
}

func TestTag(t *testing.T) {
Expand Down

0 comments on commit 4af927b

Please sign in to comment.