Skip to content

Commit 49f2962

Browse files
committed
11
1 parent 1f9c908 commit 49f2962

13 files changed

Lines changed: 58 additions & 132 deletions

blob.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,5 @@ func (b *Blob) Bytes(ctx context.Context) ([]byte, error) {
3333

3434
// Pipe reads the content of the blob and pipes stdout to the supplied io.Writer.
3535
func (b *Blob) Pipe(ctx context.Context, stdout io.Writer) error {
36-
return pipe(ctx, b.parent.repo.path, []string{"show", b.id.String()}, nil, stdout)
36+
return pipe(ctx, b.parent.repo.path, []string{"show", "--end-of-options", b.id.String()}, nil, stdout)
3737
}

command.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ import (
1717
"github.com/sourcegraph/run"
1818
)
1919

20-
// CommandOptions contains options for running a command.
20+
// CommandOptions contains additional options for running a Git command.
2121
type CommandOptions struct {
22-
Args []string
22+
// The additional environment variables to be passed to the underlying Git.
2323
Envs []string
2424
}
2525

repo.go

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ func Init(ctx context.Context, path string, opts ...InitOptions) error {
7575
}
7676

7777
args := []string{"init"}
78-
args = append(args, opt.Args...)
7978
if opt.Bare {
8079
args = append(args, "--bare")
8180
}
@@ -133,7 +132,6 @@ func Clone(ctx context.Context, url, dst string, opts ...CloneOptions) error {
133132
}
134133

135134
args := []string{"clone"}
136-
args = append(args, opt.Args...)
137135
if opt.Mirror {
138136
args = append(args, "--mirror")
139137
}
@@ -173,10 +171,10 @@ func (r *Repository) Fetch(ctx context.Context, opts ...FetchOptions) error {
173171
}
174172

175173
args := []string{"fetch"}
176-
args = append(args, opt.Args...)
177174
if opt.Prune {
178175
args = append(args, "--prune")
179176
}
177+
args = append(args, "--end-of-options")
180178

181179
_, err := exec(ctx, r.path, args, opt.Envs)
182180
return err
@@ -206,13 +204,13 @@ func (r *Repository) Pull(ctx context.Context, opts ...PullOptions) error {
206204
}
207205

208206
args := []string{"pull"}
209-
args = append(args, opt.Args...)
210207
if opt.Rebase {
211208
args = append(args, "--rebase")
212209
}
213210
if opt.All {
214211
args = append(args, "--all")
215212
}
213+
args = append(args, "--end-of-options")
216214
if !opt.All && opt.Remote != "" {
217215
args = append(args, opt.Remote)
218216
if opt.Branch != "" {
@@ -239,9 +237,7 @@ func (r *Repository) Push(ctx context.Context, remote, branch string, opts ...Pu
239237
opt = opts[0]
240238
}
241239

242-
args := []string{"push"}
243-
args = append(args, opt.Args...)
244-
args = append(args, "--end-of-options", remote, branch)
240+
args := []string{"push", "--end-of-options", remote, branch}
245241
_, err := exec(ctx, r.path, args, opt.Envs)
246242
return err
247243
}
@@ -264,13 +260,10 @@ func (r *Repository) Checkout(ctx context.Context, branch string, opts ...Checko
264260
}
265261

266262
args := []string{"checkout"}
267-
args = append(args, opt.Args...)
268-
if opt.BaseBranch != "" {
269-
args = append(args, "-b")
270-
}
271-
args = append(args, branch)
272263
if opt.BaseBranch != "" {
273-
args = append(args, opt.BaseBranch)
264+
args = append(args, "-b", branch, "--end-of-options", opt.BaseBranch)
265+
} else {
266+
args = append(args, "--end-of-options", branch)
274267
}
275268

276269
_, err := exec(ctx, r.path, args, opt.Envs)
@@ -298,7 +291,6 @@ func (r *Repository) Reset(ctx context.Context, rev string, opts ...ResetOptions
298291
if opt.Hard {
299292
args = append(args, "--hard")
300293
}
301-
args = append(args, opt.Args...)
302294
args = append(args, "--end-of-options", rev)
303295

304296
_, err := exec(ctx, r.path, args, opt.Envs)
@@ -322,9 +314,7 @@ func (r *Repository) Move(ctx context.Context, src, dst string, opts ...MoveOpti
322314
opt = opts[0]
323315
}
324316

325-
args := []string{"mv"}
326-
args = append(args, opt.Args...)
327-
args = append(args, "--end-of-options", src, dst)
317+
args := []string{"mv", "--end-of-options", src, dst}
328318
_, err := exec(ctx, r.path, args, opt.Envs)
329319
return err
330320
}
@@ -349,7 +339,6 @@ func (r *Repository) Add(ctx context.Context, opts ...AddOptions) error {
349339
}
350340

351341
args := []string{"add"}
352-
args = append(args, opt.Args...)
353342
if opt.All {
354343
args = append(args, "--all")
355344
}
@@ -389,7 +378,7 @@ func (r *Repository) Commit(ctx context.Context, committer *Signature, message s
389378
args := []string{"commit"}
390379
args = append(args, fmt.Sprintf("--author=%s <%s>", opt.Author.Name, opt.Author.Email))
391380
args = append(args, "-m", message)
392-
args = append(args, opt.Args...)
381+
args = append(args, "--end-of-options")
393382

394383
_, err := exec(ctx, r.path, args, envs)
395384
// No stderr but exit status 1 means nothing to commit.
@@ -444,9 +433,7 @@ func (r *Repository) ShowNameStatus(ctx context.Context, rev string, opts ...Sho
444433
done <- struct{}{}
445434
}()
446435

447-
args := []string{"show", "--name-status", "--pretty=format:''"}
448-
args = append(args, opt.Args...)
449-
args = append(args, "--end-of-options", rev)
436+
args := []string{"show", "--name-status", "--pretty=format:''", "--end-of-options", rev}
450437

451438
err := pipe(ctx, r.path, args, opt.Envs, w)
452439
_ = w.Close() // Close writer to exit parsing goroutine
@@ -474,9 +461,7 @@ func (r *Repository) RevParse(ctx context.Context, rev string, opts ...RevParseO
474461
opt = opts[0]
475462
}
476463

477-
args := []string{"rev-parse"}
478-
args = append(args, opt.Args...)
479-
args = append(args, rev)
464+
args := []string{"rev-parse", rev}
480465

481466
commitID, err := exec(ctx, r.path, args, opt.Envs)
482467
if err != nil {
@@ -515,8 +500,7 @@ func (r *Repository) CountObjects(ctx context.Context, opts ...CountObjectsOptio
515500
opt = opts[0]
516501
}
517502

518-
args := []string{"count-objects", "-v"}
519-
args = append(args, opt.Args...)
503+
args := []string{"count-objects", "-v", "--end-of-options"}
520504

521505
stdout, err := exec(ctx, r.path, args, opt.Envs)
522506
if err != nil {
@@ -569,8 +553,7 @@ func (r *Repository) Fsck(ctx context.Context, opts ...FsckOptions) error {
569553
opt = opts[0]
570554
}
571555

572-
args := []string{"fsck"}
573-
args = append(args, opt.Args...)
556+
args := []string{"fsck", "--end-of-options"}
574557
_, err := exec(ctx, r.path, args, opt.Envs)
575558
return err
576559
}

repo_blame.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@ func (r *Repository) Blame(ctx context.Context, rev, file string, opts ...BlameO
2424
opt = opts[0]
2525
}
2626

27-
args := []string{"blame"}
28-
args = append(args, opt.Args...)
29-
args = append(args, "-l", "-s", rev, "--", file)
27+
args := []string{"blame", "-l", "-s", rev, "--", file}
3028

3129
stdout, err := exec(ctx, r.path, args, opt.Envs)
3230
if err != nil {

repo_commit.go

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,7 @@ func (r *Repository) CatFileCommit(ctx context.Context, rev string, opts ...CatF
9494
return nil, err
9595
}
9696

97-
args := []string{"cat-file"}
98-
args = append(args, opt.Args...)
99-
args = append(args, "commit", commitID)
97+
args := []string{"cat-file", "commit", commitID}
10098

10199
stdout, err := exec(ctx, r.path, args, opt.Envs)
102100
if err != nil {
@@ -129,9 +127,7 @@ func (r *Repository) CatFileType(ctx context.Context, rev string, opts ...CatFil
129127
opt = opts[0]
130128
}
131129

132-
args := []string{"cat-file"}
133-
args = append(args, opt.Args...)
134-
args = append(args, "-t", rev)
130+
args := []string{"cat-file", "-t", rev}
135131

136132
typ, err := exec(ctx, r.path, args, opt.Envs)
137133
if err != nil {
@@ -193,9 +189,7 @@ func (r *Repository) Log(ctx context.Context, rev string, opts ...LogOptions) ([
193189
opt = opts[0]
194190
}
195191

196-
args := []string{"log"}
197-
args = append(args, opt.Args...)
198-
args = append(args, "--pretty="+LogFormatHashOnly)
192+
args := []string{"log", "--pretty=" + LogFormatHashOnly}
199193
if opt.MaxCount > 0 {
200194
args = append(args, "--max-count="+strconv.Itoa(opt.MaxCount))
201195
}
@@ -358,9 +352,7 @@ func (r *Repository) DiffNameOnly(ctx context.Context, base, head string, opts .
358352
opt = opts[0]
359353
}
360354

361-
args := []string{"diff"}
362-
args = append(args, opt.Args...)
363-
args = append(args, "--name-only", "--end-of-options")
355+
args := []string{"diff", "--name-only", "--end-of-options"}
364356
if opt.NeedsMergeBase {
365357
args = append(args, base+"..."+head)
366358
} else {
@@ -410,9 +402,7 @@ func (r *Repository) RevListCount(ctx context.Context, refspecs []string, opts .
410402
return 0, errors.New("must have at least one refspec")
411403
}
412404

413-
args := []string{"rev-list"}
414-
args = append(args, opt.Args...)
415-
args = append(args, "--count", "--end-of-options")
405+
args := []string{"rev-list", "--count", "--end-of-options"}
416406
args = append(args, refspecs...)
417407
args = append(args, "--")
418408
if opt.Path != "" {
@@ -449,9 +439,7 @@ func (r *Repository) RevList(ctx context.Context, refspecs []string, opts ...Rev
449439
return nil, errors.New("must have at least one refspec")
450440
}
451441

452-
args := []string{"rev-list"}
453-
args = append(args, opt.Args...)
454-
args = append(args, "--end-of-options")
442+
args := []string{"rev-list", "--end-of-options"}
455443
args = append(args, refspecs...)
456444
args = append(args, "--")
457445
if opt.Path != "" {
@@ -481,9 +469,7 @@ func (r *Repository) LatestCommitTime(ctx context.Context, opts ...LatestCommitT
481469
opt = opts[0]
482470
}
483471

484-
args := []string{"for-each-ref"}
485-
args = append(args, opt.Args...)
486-
args = append(args, "--count=1", "--sort=-committerdate", "--format=%(committerdate:iso8601)")
472+
args := []string{"for-each-ref", "--count=1", "--sort=-committerdate", "--format=%(committerdate:iso8601)", "--end-of-options"}
487473
if opt.Branch != "" {
488474
args = append(args, RefsHeads+opt.Branch)
489475
}

repo_diff.go

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ type DiffOptions struct {
1717
// The commit ID to used for computing diff between a range of commits (base,
1818
// revision]. When not set, only computes diff for a single commit at revision.
1919
Base string
20-
// The additional options to be passed to the underlying git.
20+
// The additional options to be passed to the underlying Git.
2121
CommandOptions
2222
}
2323

@@ -37,22 +37,16 @@ func (r *Repository) Diff(ctx context.Context, rev string, maxFiles, maxFileLine
3737
if opt.Base == "" {
3838
// First commit of repository
3939
if commit.ParentsCount() == 0 {
40-
args = []string{"show"}
41-
args = append(args, opt.Args...)
42-
args = append(args, "--full-index", "--end-of-options", rev)
40+
args = []string{"show", "--full-index", "--end-of-options", rev}
4341
} else {
4442
c, err := commit.Parent(ctx, 0)
4543
if err != nil {
4644
return nil, err
4745
}
48-
args = []string{"diff"}
49-
args = append(args, opt.Args...)
50-
args = append(args, "--full-index", "-M", c.ID.String(), "--end-of-options", rev)
46+
args = []string{"diff", "--full-index", "-M", c.ID.String(), "--end-of-options", rev}
5147
}
5248
} else {
53-
args = []string{"diff"}
54-
args = append(args, opt.Args...)
55-
args = append(args, "--full-index", "-M", opt.Base, "--end-of-options", rev)
49+
args = []string{"diff", "--full-index", "-M", opt.Base, "--end-of-options", rev}
5650
}
5751

5852
stdout, w := io.Pipe()
@@ -81,7 +75,7 @@ const (
8175
//
8276
// Docs: https://git-scm.com/docs/git-format-patch
8377
type RawDiffOptions struct {
84-
// The additional options to be passed to the underlying git.
78+
// The additional options to be passed to the underlying Git.
8579
CommandOptions
8680
}
8781

@@ -102,31 +96,23 @@ func (r *Repository) RawDiff(ctx context.Context, rev string, diffType RawDiffFo
10296
switch diffType {
10397
case RawDiffNormal:
10498
if commit.ParentsCount() == 0 {
105-
args = []string{"show"}
106-
args = append(args, opt.Args...)
107-
args = append(args, "--full-index", "--end-of-options", rev)
99+
args = []string{"show", "--full-index", "--end-of-options", rev}
108100
} else {
109101
c, err := commit.Parent(ctx, 0)
110102
if err != nil {
111103
return err
112104
}
113-
args = []string{"diff"}
114-
args = append(args, opt.Args...)
115-
args = append(args, "--full-index", "-M", c.ID.String(), "--end-of-options", rev)
105+
args = []string{"diff", "--full-index", "-M", c.ID.String(), "--end-of-options", rev}
116106
}
117107
case RawDiffPatch:
118108
if commit.ParentsCount() == 0 {
119-
args = []string{"format-patch"}
120-
args = append(args, opt.Args...)
121-
args = append(args, "--full-index", "--no-signoff", "--no-signature", "--stdout", "--root", "--end-of-options", rev)
109+
args = []string{"format-patch", "--full-index", "--no-signoff", "--no-signature", "--stdout", "--root", "--end-of-options", rev}
122110
} else {
123111
c, err := commit.Parent(ctx, 0)
124112
if err != nil {
125113
return err
126114
}
127-
args = []string{"format-patch"}
128-
args = append(args, opt.Args...)
129-
args = append(args, "--full-index", "--no-signoff", "--no-signature", "--stdout", "--end-of-options", rev+"..."+c.ID.String())
115+
args = []string{"format-patch", "--full-index", "--no-signoff", "--no-signature", "--stdout", "--end-of-options", rev + "..." + c.ID.String()}
130116
}
131117
default:
132118
return fmt.Errorf("invalid diffType: %s", diffType)
@@ -140,7 +126,7 @@ func (r *Repository) RawDiff(ctx context.Context, rev string, diffType RawDiffFo
140126

141127
// DiffBinaryOptions contains optional arguments for producing binary patch.
142128
type DiffBinaryOptions struct {
143-
// The additional options to be passed to the underlying git.
129+
// The additional options to be passed to the underlying Git.
144130
CommandOptions
145131
}
146132

@@ -152,9 +138,6 @@ func (r *Repository) DiffBinary(ctx context.Context, base, head string, opts ...
152138
opt = opts[0]
153139
}
154140

155-
args := []string{"diff"}
156-
args = append(args, opt.Args...)
157-
args = append(args, "--full-index", "--binary", "--end-of-options", base, head)
158-
141+
args := []string{"diff", "--full-index", "--binary", "--end-of-options", base, head}
159142
return exec(ctx, r.path, args, opt.Envs)
160143
}

repo_grep.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ type GrepOptions struct {
2525
WordRegexp bool
2626
// Whether use extended regular expressions.
2727
ExtendedRegexp bool
28-
// The additional options to be passed to the underlying git.
28+
// The additional options to be passed to the underlying Git.
2929
CommandOptions
3030
}
3131

@@ -79,7 +79,6 @@ func (r *Repository) Grep(ctx context.Context, pattern string, opts ...GrepOptio
7979
}
8080

8181
args := []string{"grep"}
82-
args = append(args, opt.Args...)
8382
// Display full-name, line number and column number
8483
args = append(args, "--full-name", "--line-number", "--column")
8584
if opt.IgnoreCase {

repo_pull.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ func (r *Repository) MergeBase(ctx context.Context, base, head string, opts ...M
2626
}
2727

2828
args := []string{"merge-base"}
29-
args = append(args, opt.Args...)
3029
args = append(args, "--end-of-options", base, head)
3130

3231
stdout, err := exec(ctx, r.path, args, opt.Envs)

0 commit comments

Comments
 (0)