@@ -76,6 +76,7 @@ type CloneRepoOptions struct {
7676 Bare bool
7777 Quiet bool
7878 Timeout time.Duration
79+ Branch string
7980}
8081
8182// Clone clones original repository to target path.
@@ -95,6 +96,9 @@ func Clone(from, to string, opts CloneRepoOptions) (err error) {
9596 if opts .Quiet {
9697 cmd .AddArguments ("--quiet" )
9798 }
99+ if len (opts .Branch ) > 0 {
100+ cmd .AddArguments ("-b" , opts .Branch )
101+ }
98102 cmd .AddArguments (from , to )
99103
100104 if opts .Timeout <= 0 {
@@ -107,6 +111,8 @@ func Clone(from, to string, opts CloneRepoOptions) (err error) {
107111
108112type PullRemoteOptions struct {
109113 All bool
114+ Remote string
115+ Branch string
110116 Timeout time.Duration
111117}
112118
@@ -115,6 +121,9 @@ func Pull(repoPath string, opts PullRemoteOptions) error {
115121 cmd := NewCommand ("pull" )
116122 if opts .All {
117123 cmd .AddArguments ("--all" )
124+ } else {
125+ cmd .AddArguments (opts .Remote )
126+ cmd .AddArguments (opts .Branch )
118127 }
119128
120129 if opts .Timeout <= 0 {
@@ -131,6 +140,33 @@ func Push(repoPath, remote, branch string) error {
131140 return err
132141}
133142
143+ type CheckoutOptions struct {
144+ Branch string
145+ OldBranch string
146+ Timeout time.Duration
147+ }
148+
149+ // Checkout checkouts a branch
150+ func Checkout (repoPath string , opts CheckoutOptions ) error {
151+ cmd := NewCommand ("checkout" )
152+ if len (opts .OldBranch ) > 0 {
153+ cmd .AddArguments ("-b" )
154+ }
155+
156+ if opts .Timeout <= 0 {
157+ opts .Timeout = - 1
158+ }
159+
160+ cmd .AddArguments (opts .Branch )
161+
162+ if len (opts .OldBranch ) > 0 {
163+ cmd .AddArguments (opts .OldBranch )
164+ }
165+
166+ _ , err := cmd .RunInDirTimeout (opts .Timeout , repoPath )
167+ return err
168+ }
169+
134170// ResetHEAD resets HEAD to given revision or head of branch.
135171func ResetHEAD (repoPath string , hard bool , revision string ) error {
136172 cmd := NewCommand ("reset" )
@@ -140,3 +176,11 @@ func ResetHEAD(repoPath string, hard bool, revision string) error {
140176 _ , err := cmd .AddArguments (revision ).RunInDir (repoPath )
141177 return err
142178}
179+
180+ // MoveFile moves a file to another file or directory
181+ func MoveFile (repoPath , oldTreeName , newTreeName string ) error {
182+ cmd := NewCommand ("mv" )
183+ cmd .AddArguments (oldTreeName , newTreeName )
184+ _ , err := cmd .RunInDir (repoPath )
185+ return err
186+ }
0 commit comments