@@ -221,17 +221,25 @@ type PushOptions struct {
221
221
Timeout time.Duration
222
222
}
223
223
224
- // Push pushs local changes to given remote and branch for the repository.
225
- func (r * Repository ) Push (remote , branch string , opts ... PushOptions ) error {
224
+ // RepoPush pushs local changes to given remote and branch for the repository
225
+ // in given path.
226
+ func RepoPush (repoPath , remote , branch string , opts ... PushOptions ) error {
226
227
var opt PushOptions
227
228
if len (opts ) > 0 {
228
229
opt = opts [0 ]
229
230
}
230
231
231
- _ , err := NewCommand ("push" , remote , branch ).AddEnvs (opt .Envs ... ).RunInDirWithTimeout (opt .Timeout , r .path )
232
+ _ , err := NewCommand ("push" , remote , branch ).
233
+ AddEnvs (opt .Envs ... ).
234
+ RunInDirWithTimeout (opt .Timeout , repoPath )
232
235
return err
233
236
}
234
237
238
+ // Push pushs local changes to given remote and branch for the repository.
239
+ func (r * Repository ) Push (remote , branch string , opts ... PushOptions ) error {
240
+ return RepoPush (r .path , remote , branch , opts ... )
241
+ }
242
+
235
243
// CheckoutOptions contains optional arguments for checking out to a branch.
236
244
// Docs: https://git-scm.com/docs/git-checkout
237
245
type CheckoutOptions struct {
@@ -242,8 +250,8 @@ type CheckoutOptions struct {
242
250
Timeout time.Duration
243
251
}
244
252
245
- // Checkout checks out to given branch for the repository.
246
- func ( r * Repository ) Checkout ( branch string , opts ... CheckoutOptions ) error {
253
+ // Checkout checks out to given branch for the repository in given path .
254
+ func RepoCheckout ( repoPath , branch string , opts ... CheckoutOptions ) error {
247
255
var opt CheckoutOptions
248
256
if len (opts ) > 0 {
249
257
opt = opts [0 ]
@@ -258,10 +266,15 @@ func (r *Repository) Checkout(branch string, opts ...CheckoutOptions) error {
258
266
cmd .AddArgs (opt .BaseBranch )
259
267
}
260
268
261
- _ , err := cmd .RunInDirWithTimeout (opt .Timeout , r . path )
269
+ _ , err := cmd .RunInDirWithTimeout (opt .Timeout , repoPath )
262
270
return err
263
271
}
264
272
273
+ // Checkout checks out to given branch for the repository.
274
+ func (r * Repository ) Checkout (branch string , opts ... CheckoutOptions ) error {
275
+ return RepoCheckout (r .path , branch , opts ... )
276
+ }
277
+
265
278
// ResetOptions contains optional arguments for resetting a branch.
266
279
// Docs: https://git-scm.com/docs/git-reset
267
280
type ResetOptions struct {
@@ -272,8 +285,8 @@ type ResetOptions struct {
272
285
Timeout time.Duration
273
286
}
274
287
275
- // Reset resets working tree to given revision for the repository.
276
- func ( r * Repository ) Reset ( rev string , opts ... ResetOptions ) error {
288
+ // RepoReset resets working tree to given revision for the repository in given path .
289
+ func RepoReset ( repoPath , rev string , opts ... ResetOptions ) error {
277
290
var opt ResetOptions
278
291
if len (opts ) > 0 {
279
292
opt = opts [0 ]
@@ -284,10 +297,15 @@ func (r *Repository) Reset(rev string, opts ...ResetOptions) error {
284
297
cmd .AddArgs ("--hard" )
285
298
}
286
299
287
- _ , err := cmd .AddArgs (rev ).RunInDir (r . path )
300
+ _ , err := cmd .AddArgs (rev ).RunInDir (repoPath )
288
301
return err
289
302
}
290
303
304
+ // Reset resets working tree to given revision for the repository.
305
+ func (r * Repository ) Reset (rev string , opts ... ResetOptions ) error {
306
+ return RepoReset (r .path , rev , opts ... )
307
+ }
308
+
291
309
// MoveOptions contains optional arguments for moving a file, a directory, or a symlink.
292
310
// Docs: https://git-scm.com/docs/git-mv
293
311
type MoveOptions struct {
@@ -296,17 +314,24 @@ type MoveOptions struct {
296
314
Timeout time.Duration
297
315
}
298
316
299
- // Move moves a file, a directory, or a symlink file or directory from source to destination.
300
- func (r * Repository ) Move (src , dst string , opts ... MoveOptions ) error {
317
+ // RepoMove moves a file, a directory, or a symlink file or directory from source to
318
+ // destination for the repository in given path.
319
+ func RepoMove (repoPath , src , dst string , opts ... MoveOptions ) error {
301
320
var opt MoveOptions
302
321
if len (opts ) > 0 {
303
322
opt = opts [0 ]
304
323
}
305
324
306
- _ , err := NewCommand ("mv" , src , dst ).RunInDirWithTimeout (opt .Timeout , r . path )
325
+ _ , err := NewCommand ("mv" , src , dst ).RunInDirWithTimeout (opt .Timeout , repoPath )
307
326
return err
308
327
}
309
328
329
+ // Move moves a file, a directory, or a symlink file or directory from source to destination
330
+ // for the repository.
331
+ func (r * Repository ) Move (src , dst string , opts ... MoveOptions ) error {
332
+ return RepoMove (r .path , src , dst , opts ... )
333
+ }
334
+
310
335
// AddOptions contains optional arguments for adding local changes.
311
336
// Docs: https://git-scm.com/docs/git-add
312
337
type AddOptions struct {
@@ -319,8 +344,8 @@ type AddOptions struct {
319
344
Timeout time.Duration
320
345
}
321
346
322
- // Add adds local changes to index for the repository.
323
- func ( r * Repository ) Add ( opts ... AddOptions ) error {
347
+ // RepoAdd adds local changes to index for the repository in given path .
348
+ func RepoAdd ( repoPath string , opts ... AddOptions ) error {
324
349
var opt AddOptions
325
350
if len (opts ) > 0 {
326
351
opt = opts [0 ]
@@ -334,10 +359,15 @@ func (r *Repository) Add(opts ...AddOptions) error {
334
359
cmd .AddArgs ("--" )
335
360
cmd .AddArgs (opt .Pathsepcs ... )
336
361
}
337
- _ , err := cmd .RunInDirWithTimeout (opt .Timeout , r . path )
362
+ _ , err := cmd .RunInDirWithTimeout (opt .Timeout , repoPath )
338
363
return err
339
364
}
340
365
366
+ // Add adds local changes to index for the repository.
367
+ func (r * Repository ) Add (opts ... AddOptions ) error {
368
+ return RepoAdd (r .path , opts ... )
369
+ }
370
+
341
371
// CommitOptions contains optional arguments to commit changes.
342
372
// Docs: https://git-scm.com/docs/git-commit
343
373
type CommitOptions struct {
@@ -348,8 +378,9 @@ type CommitOptions struct {
348
378
Timeout time.Duration
349
379
}
350
380
351
- // Commit commits local changes with given author, committer and message for the repository.
352
- func (r * Repository ) Commit (committer * Signature , message string , opts ... CommitOptions ) error {
381
+ // RepoCommit commits local changes with given author, committer and message for the
382
+ // repository in given path.
383
+ func RepoCommit (repoPath string , committer * Signature , message string , opts ... CommitOptions ) error {
353
384
var opt CommitOptions
354
385
if len (opts ) > 0 {
355
386
opt = opts [0 ]
@@ -363,14 +394,19 @@ func (r *Repository) Commit(committer *Signature, message string, opts ...Commit
363
394
}
364
395
cmd .AddArgs ("-m" , message )
365
396
366
- _ , err := cmd .RunInDirWithTimeout (opt .Timeout , r . path )
397
+ _ , err := cmd .RunInDirWithTimeout (opt .Timeout , repoPath )
367
398
// No stderr but exit status 1 means nothing to commit.
368
399
if err != nil && err .Error () == "exit status 1" {
369
400
return nil
370
401
}
371
402
return err
372
403
}
373
404
405
+ // Commit commits local changes with given author, committer and message for the repository.
406
+ func (r * Repository ) Commit (committer * Signature , message string , opts ... CommitOptions ) error {
407
+ return RepoCommit (r .path , committer , message , opts ... )
408
+ }
409
+
374
410
// NameStatus contains name status of a commit.
375
411
type NameStatus struct {
376
412
Added []string
0 commit comments