Skip to content

Commit af7717c

Browse files
committed
refactor: refactor git command handling and improve code clarity
- Remove single quotes from the --since and --until options in git command invocations - Refactor command chaining for improved readability in repo_stats.go - Remove an unused TODO comment from the commits test file Signed-off-by: Bo-Yi Wu <[email protected]>
1 parent 9deef2d commit af7717c

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

modules/git/repo_commit.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,10 @@ func (repo *Repository) commitsByRangeWithTime(id ObjectID, page, pageSize int,
101101
cmd.AddOptionValues("--not", not)
102102
}
103103
if since != "" {
104-
cmd.AddOptionFormat("--since='%s'", since)
104+
cmd.AddOptionFormat("--since=%s", since)
105105
}
106106
if until != "" {
107-
cmd.AddOptionFormat("--until='%s'", until)
107+
cmd.AddOptionFormat("--until=%s", until)
108108
}
109109

110110
stdout, _, err := cmd.RunStdBytes(repo.Ctx, &RunOpts{Dir: repo.Path})

modules/git/repo_stats.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ func (repo *Repository) GetCodeActivityStats(fromTime time.Time, branch string)
4040

4141
since := fromTime.Format(time.RFC3339)
4242

43-
stdout, _, runErr := NewCommand("rev-list", "--count", "--no-merges", "--branches=*", "--date=iso").AddOptionFormat("--since='%s'", since).RunStdString(repo.Ctx, &RunOpts{Dir: repo.Path})
43+
stdout, _, runErr := NewCommand("rev-list", "--count", "--no-merges", "--branches=*", "--date=iso").
44+
AddOptionFormat("--since=%s", since).
45+
RunStdString(repo.Ctx, &RunOpts{Dir: repo.Path})
4446
if runErr != nil {
4547
return nil, runErr
4648
}
@@ -60,7 +62,8 @@ func (repo *Repository) GetCodeActivityStats(fromTime time.Time, branch string)
6062
_ = stdoutWriter.Close()
6163
}()
6264

63-
gitCmd := NewCommand("log", "--numstat", "--no-merges", "--pretty=format:---%n%h%n%aN%n%aE%n", "--date=iso").AddOptionFormat("--since='%s'", since)
65+
gitCmd := NewCommand("log", "--numstat", "--no-merges", "--pretty=format:---%n%h%n%aN%n%aE%n", "--date=iso").
66+
AddOptionFormat("--since=%s", since)
6467
if len(branch) == 0 {
6568
gitCmd.AddArguments("--branches=*")
6669
} else {

modules/repository/commits_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,5 +200,3 @@ func TestListToPushCommits(t *testing.T) {
200200
assert.Equal(t, now, pushCommits.Commits[1].Timestamp)
201201
}
202202
}
203-
204-
// TODO TestPushUpdate

0 commit comments

Comments
 (0)