@@ -221,17 +221,25 @@ type PushOptions struct {
221221 Timeout time.Duration
222222}
223223
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 {
226227 var opt PushOptions
227228 if len (opts ) > 0 {
228229 opt = opts [0 ]
229230 }
230231
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 )
232235 return err
233236}
234237
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+
235243// CheckoutOptions contains optional arguments for checking out to a branch.
236244// Docs: https://git-scm.com/docs/git-checkout
237245type CheckoutOptions struct {
@@ -242,8 +250,8 @@ type CheckoutOptions struct {
242250 Timeout time.Duration
243251}
244252
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 {
247255 var opt CheckoutOptions
248256 if len (opts ) > 0 {
249257 opt = opts [0 ]
@@ -258,10 +266,15 @@ func (r *Repository) Checkout(branch string, opts ...CheckoutOptions) error {
258266 cmd .AddArgs (opt .BaseBranch )
259267 }
260268
261- _ , err := cmd .RunInDirWithTimeout (opt .Timeout , r . path )
269+ _ , err := cmd .RunInDirWithTimeout (opt .Timeout , repoPath )
262270 return err
263271}
264272
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+
265278// ResetOptions contains optional arguments for resetting a branch.
266279// Docs: https://git-scm.com/docs/git-reset
267280type ResetOptions struct {
@@ -272,8 +285,8 @@ type ResetOptions struct {
272285 Timeout time.Duration
273286}
274287
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 {
277290 var opt ResetOptions
278291 if len (opts ) > 0 {
279292 opt = opts [0 ]
@@ -284,10 +297,15 @@ func (r *Repository) Reset(rev string, opts ...ResetOptions) error {
284297 cmd .AddArgs ("--hard" )
285298 }
286299
287- _ , err := cmd .AddArgs (rev ).RunInDir (r . path )
300+ _ , err := cmd .AddArgs (rev ).RunInDir (repoPath )
288301 return err
289302}
290303
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+
291309// MoveOptions contains optional arguments for moving a file, a directory, or a symlink.
292310// Docs: https://git-scm.com/docs/git-mv
293311type MoveOptions struct {
@@ -296,17 +314,24 @@ type MoveOptions struct {
296314 Timeout time.Duration
297315}
298316
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 {
301320 var opt MoveOptions
302321 if len (opts ) > 0 {
303322 opt = opts [0 ]
304323 }
305324
306- _ , err := NewCommand ("mv" , src , dst ).RunInDirWithTimeout (opt .Timeout , r . path )
325+ _ , err := NewCommand ("mv" , src , dst ).RunInDirWithTimeout (opt .Timeout , repoPath )
307326 return err
308327}
309328
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+
310335// AddOptions contains optional arguments for adding local changes.
311336// Docs: https://git-scm.com/docs/git-add
312337type AddOptions struct {
@@ -319,8 +344,8 @@ type AddOptions struct {
319344 Timeout time.Duration
320345}
321346
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 {
324349 var opt AddOptions
325350 if len (opts ) > 0 {
326351 opt = opts [0 ]
@@ -334,10 +359,15 @@ func (r *Repository) Add(opts ...AddOptions) error {
334359 cmd .AddArgs ("--" )
335360 cmd .AddArgs (opt .Pathsepcs ... )
336361 }
337- _ , err := cmd .RunInDirWithTimeout (opt .Timeout , r . path )
362+ _ , err := cmd .RunInDirWithTimeout (opt .Timeout , repoPath )
338363 return err
339364}
340365
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+
341371// CommitOptions contains optional arguments to commit changes.
342372// Docs: https://git-scm.com/docs/git-commit
343373type CommitOptions struct {
@@ -348,8 +378,9 @@ type CommitOptions struct {
348378 Timeout time.Duration
349379}
350380
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 {
353384 var opt CommitOptions
354385 if len (opts ) > 0 {
355386 opt = opts [0 ]
@@ -363,14 +394,19 @@ func (r *Repository) Commit(committer *Signature, message string, opts ...Commit
363394 }
364395 cmd .AddArgs ("-m" , message )
365396
366- _ , err := cmd .RunInDirWithTimeout (opt .Timeout , r . path )
397+ _ , err := cmd .RunInDirWithTimeout (opt .Timeout , repoPath )
367398 // No stderr but exit status 1 means nothing to commit.
368399 if err != nil && err .Error () == "exit status 1" {
369400 return nil
370401 }
371402 return err
372403}
373404
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+
374410// NameStatus contains name status of a commit.
375411type NameStatus struct {
376412 Added []string
0 commit comments