Skip to content

Commit d5f694f

Browse files
unknwonclaude
andauthored
Add Push.SetUpstream option and worktree support (#132)
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 9f4d314 commit d5f694f

15 files changed

+141
-53
lines changed

repo.go

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ func (r *Repository) parsePrettyFormatLogToList(ctx context.Context, logs []byte
5454
type InitOptions struct {
5555
// Indicates whether the repository should be initialized in bare format.
5656
Bare bool
57-
// The additional options to be passed to the underlying git.
5857
CommandOptions
5958
}
6059

@@ -111,7 +110,6 @@ type CloneOptions struct {
111110
Branch string
112111
// The number of revisions to clone.
113112
Depth uint64
114-
// The additional options to be passed to the underlying git.
115113
CommandOptions
116114
}
117115

@@ -155,7 +153,6 @@ func Clone(ctx context.Context, url, dst string, opts ...CloneOptions) error {
155153
type FetchOptions struct {
156154
// Indicates whether to prune during fetching.
157155
Prune bool
158-
// The additional options to be passed to the underlying git.
159156
CommandOptions
160157
}
161158

@@ -188,7 +185,6 @@ type PullOptions struct {
188185
Remote string
189186
// The branch to pull updates from when All=false and Remote is supplied.
190187
Branch string
191-
// The additional options to be passed to the underlying git.
192188
CommandOptions
193189
}
194190

@@ -222,7 +218,8 @@ func (r *Repository) Pull(ctx context.Context, opts ...PullOptions) error {
222218
//
223219
// Docs: https://git-scm.com/docs/git-push
224220
type PushOptions struct {
225-
// The additional options to be passed to the underlying git.
221+
// Indicates whether to set upstream tracking for the branch.
222+
SetUpstream bool
226223
CommandOptions
227224
}
228225

@@ -233,7 +230,11 @@ func (r *Repository) Push(ctx context.Context, remote, branch string, opts ...Pu
233230
opt = opts[0]
234231
}
235232

236-
args := []string{"push", "--end-of-options", remote, branch}
233+
args := []string{"push"}
234+
if opt.SetUpstream {
235+
args = append(args, "-u")
236+
}
237+
args = append(args, "--end-of-options", remote, branch)
237238
_, err := exec(ctx, r.path, args, opt.Envs)
238239
return err
239240
}
@@ -244,7 +245,6 @@ func (r *Repository) Push(ctx context.Context, remote, branch string, opts ...Pu
244245
type CheckoutOptions struct {
245246
// The base branch if checks out to a new branch.
246247
BaseBranch string
247-
// The additional options to be passed to the underlying git.
248248
CommandOptions
249249
}
250250

@@ -272,7 +272,6 @@ func (r *Repository) Checkout(ctx context.Context, branch string, opts ...Checko
272272
type ResetOptions struct {
273273
// Indicates whether to perform a hard reset.
274274
Hard bool
275-
// The additional options to be passed to the underlying git.
276275
CommandOptions
277276
}
278277

@@ -298,7 +297,6 @@ func (r *Repository) Reset(ctx context.Context, rev string, opts ...ResetOptions
298297
//
299298
// Docs: https://git-scm.com/docs/git-mv
300299
type MoveOptions struct {
301-
// The additional options to be passed to the underlying git.
302300
CommandOptions
303301
}
304302

@@ -323,7 +321,6 @@ type AddOptions struct {
323321
All bool
324322
// The specific pathspecs to be added to index.
325323
Pathspecs []string
326-
// The additional options to be passed to the underlying git.
327324
CommandOptions
328325
}
329326

@@ -352,7 +349,6 @@ func (r *Repository) Add(ctx context.Context, opts ...AddOptions) error {
352349
type CommitOptions struct {
353350
// Author is the author of the changes if that's not the same as committer.
354351
Author *Signature
355-
// The additional options to be passed to the underlying git.
356352
CommandOptions
357353
}
358354

@@ -395,7 +391,6 @@ type NameStatus struct {
395391
//
396392
// Docs: https://git-scm.com/docs/git-show#Documentation/git-show.txt---name-status
397393
type ShowNameStatusOptions struct {
398-
// The additional options to be passed to the underlying git.
399394
CommandOptions
400395
}
401396

@@ -445,7 +440,6 @@ func (r *Repository) ShowNameStatus(ctx context.Context, rev string, opts ...Sho
445440
//
446441
// Docs: https://git-scm.com/docs/git-rev-parse
447442
type RevParseOptions struct {
448-
// The additional options to be passed to the underlying git.
449443
CommandOptions
450444
}
451445

@@ -485,7 +479,6 @@ type CountObject struct {
485479
//
486480
// Docs: https://git-scm.com/docs/git-count-objects
487481
type CountObjectsOptions struct {
488-
// The additional options to be passed to the underlying git.
489482
CommandOptions
490483
}
491484

@@ -537,7 +530,6 @@ func (r *Repository) CountObjects(ctx context.Context, opts ...CountObjectsOptio
537530
//
538531
// Docs: https://git-scm.com/docs/git-fsck
539532
type FsckOptions struct {
540-
// The additional options to be passed to the underlying git.
541533
CommandOptions
542534
}
543535

repo_blame.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
// BlameOptions contains optional arguments for blaming a file.
99
// Docs: https://git-scm.com/docs/git-blame
1010
type BlameOptions struct {
11-
// The additional options to be passed to the underlying git.
1211
CommandOptions
1312
}
1413

repo_blob.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import "context"
66
//
77
// Docs: https://git-scm.com/docs/git-cat-file#Documentation/git-cat-file.txt
88
type CatFileBlobOptions struct {
9-
// The additional options to be passed to the underlying git.
109
CommandOptions
1110
}
1211

repo_commit.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ loop:
6666
//
6767
// Docs: https://git-scm.com/docs/git-cat-file#Documentation/git-cat-file.txt-lttypegt
6868
type CatFileCommitOptions struct {
69-
// The additional options to be passed to the underlying git.
7069
CommandOptions
7170
}
7271

@@ -111,7 +110,6 @@ func (r *Repository) CatFileCommit(ctx context.Context, rev string, opts ...CatF
111110
//
112111
// Docs: https://git-scm.com/docs/git-cat-file#Documentation/git-cat-file.txt--t
113112
type CatFileTypeOptions struct {
114-
// The additional options to be passed to the underlying git.
115113
CommandOptions
116114
}
117115

@@ -159,7 +157,6 @@ type LogOptions struct {
159157
RegexpIgnoreCase bool
160158
// The relative path of the repository.
161159
Path string
162-
// The additional options to be passed to the underlying git.
163160
CommandOptions
164161
}
165162

@@ -217,7 +214,6 @@ func (r *Repository) Log(ctx context.Context, rev string, opts ...LogOptions) ([
217214
type CommitByRevisionOptions struct {
218215
// The relative path of the repository.
219216
Path string
220-
// The additional options to be passed to the underlying git.
221217
CommandOptions
222218
}
223219

@@ -251,7 +247,6 @@ func (r *Repository) CommitByRevision(ctx context.Context, rev string, opts ...C
251247
type CommitsByPageOptions struct {
252248
// The relative path of the repository.
253249
Path string
254-
// The additional options to be passed to the underlying git.
255250
CommandOptions
256251
}
257252

@@ -279,7 +274,6 @@ type SearchCommitsOptions struct {
279274
MaxCount int
280275
// The relative path of the repository.
281276
Path string
282-
// The additional options to be passed to the underlying git.
283277
CommandOptions
284278
}
285279

@@ -307,7 +301,6 @@ func (r *Repository) SearchCommits(ctx context.Context, rev, pattern string, opt
307301
type CommitsSinceOptions struct {
308302
// The relative path of the repository.
309303
Path string
310-
// The additional options to be passed to the underlying git.
311304
CommandOptions
312305
}
313306

@@ -334,7 +327,6 @@ type DiffNameOnlyOptions struct {
334327
NeedsMergeBase bool
335328
// The relative path of the repository.
336329
Path string
337-
// The additional options to be passed to the underlying git.
338330
CommandOptions
339331
}
340332

@@ -380,7 +372,6 @@ func (r *Repository) DiffNameOnly(ctx context.Context, base, head string, opts .
380372
type RevListCountOptions struct {
381373
// The relative path of the repository.
382374
Path string
383-
// The additional options to be passed to the underlying git.
384375
CommandOptions
385376
}
386377

@@ -417,7 +408,6 @@ func (r *Repository) RevListCount(ctx context.Context, refspecs []string, opts .
417408
type RevListOptions struct {
418409
// The relative path of the repository.
419410
Path string
420-
// The additional options to be passed to the underlying git.
421411
CommandOptions
422412
}
423413

@@ -452,7 +442,6 @@ func (r *Repository) RevList(ctx context.Context, refspecs []string, opts ...Rev
452442
type LatestCommitTimeOptions struct {
453443
// To get the latest commit time of the branch. When not set, it checks all branches.
454444
Branch string
455-
// The additional options to be passed to the underlying git.
456445
CommandOptions
457446
}
458447

repo_diff.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ type DiffOptions struct {
1313
// The commit ID to used for computing diff between a range of commits (base,
1414
// revision]. When not set, only computes diff for a single commit at revision.
1515
Base string
16-
// The additional options to be passed to the underlying Git.
1716
CommandOptions
1817
}
1918

@@ -71,7 +70,6 @@ const (
7170
//
7271
// Docs: https://git-scm.com/docs/git-format-patch
7372
type RawDiffOptions struct {
74-
// The additional options to be passed to the underlying Git.
7573
CommandOptions
7674
}
7775

@@ -122,7 +120,6 @@ func (r *Repository) RawDiff(ctx context.Context, rev string, diffType RawDiffFo
122120

123121
// DiffBinaryOptions contains optional arguments for producing binary patch.
124122
type DiffBinaryOptions struct {
125-
// The additional options to be passed to the underlying Git.
126123
CommandOptions
127124
}
128125

repo_grep.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ type GrepOptions struct {
2121
WordRegexp bool
2222
// Whether use extended regular expressions.
2323
ExtendedRegexp bool
24-
// The additional options to be passed to the underlying Git.
2524
CommandOptions
2625
}
2726

repo_pull.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
//
1010
// Docs: https://git-scm.com/docs/git-merge-base
1111
type MergeBaseOptions struct {
12-
// The additional options to be passed to the underlying git.
1312
CommandOptions
1413
}
1514

repo_reference.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ type Reference struct {
3333
//
3434
// Docs: https://git-scm.com/docs/git-show-ref#Documentation/git-show-ref.txt---verify
3535
type ShowRefVerifyOptions struct {
36-
// The additional options to be passed to the underlying Git.
3736
CommandOptions
3837
}
3938

@@ -96,7 +95,6 @@ type SymbolicRefOptions struct {
9695
// The name of the reference, e.g. "refs/heads/master". When set, it will be
9796
// used to update the symbolic ref.
9897
Ref string
99-
// The additional options to be passed to the underlying Git.
10098
CommandOptions
10199
}
102100

@@ -135,7 +133,6 @@ type ShowRefOptions struct {
135133
Tags bool
136134
// The list of patterns to filter results.
137135
Patterns []string
138-
// The additional options to be passed to the underlying Git.
139136
CommandOptions
140137
}
141138

@@ -198,7 +195,6 @@ func (r *Repository) Branches(ctx context.Context) ([]string, error) {
198195
type DeleteBranchOptions struct {
199196
// Indicates whether to force delete the branch.
200197
Force bool
201-
// The additional options to be passed to the underlying Git.
202198
CommandOptions
203199
}
204200

repo_remote.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ type LsRemoteOptions struct {
1919
Refs bool
2020
// The list of patterns to filter results.
2121
Patterns []string
22-
// The additional options to be passed to the underlying Git.
2322
CommandOptions
2423
}
2524

@@ -84,7 +83,6 @@ type RemoteAddOptions struct {
8483
Fetch bool
8584
// Indicates whether to add remote as mirror with --mirror=fetch.
8685
MirrorFetch bool
87-
// The additional options to be passed to the underlying Git.
8886
CommandOptions
8987
}
9088

@@ -113,7 +111,6 @@ func (r *Repository) RemoteAdd(ctx context.Context, name, url string, opts ...Re
113111
//
114112
// Docs: https://git-scm.com/docs/git-remote#Documentation/git-remote.txt-emremoveem
115113
type RemoteRemoveOptions struct {
116-
// The additional options to be passed to the underlying Git.
117114
CommandOptions
118115
}
119116

@@ -140,7 +137,6 @@ func (r *Repository) RemoteRemove(ctx context.Context, name string, opts ...Remo
140137
// /
141138
// Docs: https://git-scm.com/docs/git-remote#_commands
142139
type RemotesOptions struct {
143-
// The additional options to be passed to the underlying Git.
144140
CommandOptions
145141
}
146142

@@ -170,7 +166,6 @@ type RemoteGetURLOptions struct {
170166
// Indicates whether to get all URLs, including lists that are not part of main
171167
// URLs. This option is independent of the Push option.
172168
All bool
173-
// The additional options to be passed to the underlying Git.
174169
CommandOptions
175170
}
176171

@@ -206,7 +201,6 @@ type RemoteSetURLOptions struct {
206201
Push bool
207202
// The regex to match existing URLs to replace (instead of first).
208203
Regex string
209-
// The additional options to be passed to the underlying Git.
210204
CommandOptions
211205
}
212206

@@ -246,7 +240,6 @@ func (r *Repository) RemoteSetURL(ctx context.Context, name, newurl string, opts
246240
type RemoteSetURLAddOptions struct {
247241
// Indicates whether to get push URLs instead of fetch URLs.
248242
Push bool
249-
// The additional options to be passed to the underlying Git.
250243
CommandOptions
251244
}
252245

@@ -278,7 +271,6 @@ func (r *Repository) RemoteSetURLAdd(ctx context.Context, name, newurl string, o
278271
type RemoteSetURLDeleteOptions struct {
279272
// Indicates whether to get push URLs instead of fetch URLs.
280273
Push bool
281-
// The additional options to be passed to the underlying Git.
282274
CommandOptions
283275
}
284276

repo_tag.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ func (r *Repository) getTag(ctx context.Context, id *SHA1) (*Tag, error) {
9696
//
9797
// Docs: https://git-scm.com/docs/git-cat-file
9898
type TagOptions struct {
99-
// The additional options to be passed to the underlying git.
10099
CommandOptions
101100
}
102101

@@ -140,7 +139,6 @@ type TagsOptions struct {
140139
SortKey string
141140
// Pattern filters tags matching the specified pattern.
142141
Pattern string
143-
// The additional options to be passed to the underlying git.
144142
CommandOptions
145143
}
146144

@@ -183,7 +181,6 @@ type CreateTagOptions struct {
183181
Message string
184182
// Author is the author of the tag. It is ignored when tag is not annotated.
185183
Author *Signature
186-
// The additional options to be passed to the underlying git.
187184
CommandOptions
188185
}
189186

@@ -216,7 +213,6 @@ func (r *Repository) CreateTag(ctx context.Context, name, rev string, opts ...Cr
216213
//
217214
// Docs: https://git-scm.com/docs/git-tag#Documentation/git-tag.txt---delete
218215
type DeleteTagOptions struct {
219-
// The additional options to be passed to the underlying git.
220216
CommandOptions
221217
}
222218

0 commit comments

Comments
 (0)