@@ -76,6 +76,7 @@ type CloneRepoOptions struct {
76
76
Bare bool
77
77
Quiet bool
78
78
Timeout time.Duration
79
+ Branch string
79
80
}
80
81
81
82
// Clone clones original repository to target path.
@@ -95,6 +96,9 @@ func Clone(from, to string, opts CloneRepoOptions) (err error) {
95
96
if opts .Quiet {
96
97
cmd .AddArguments ("--quiet" )
97
98
}
99
+ if len (opts .Branch ) > 0 {
100
+ cmd .AddArguments ("-b" , opts .Branch )
101
+ }
98
102
cmd .AddArguments (from , to )
99
103
100
104
if opts .Timeout <= 0 {
@@ -107,6 +111,8 @@ func Clone(from, to string, opts CloneRepoOptions) (err error) {
107
111
108
112
type PullRemoteOptions struct {
109
113
All bool
114
+ Remote string
115
+ Branch string
110
116
Timeout time.Duration
111
117
}
112
118
@@ -115,6 +121,9 @@ func Pull(repoPath string, opts PullRemoteOptions) error {
115
121
cmd := NewCommand ("pull" )
116
122
if opts .All {
117
123
cmd .AddArguments ("--all" )
124
+ } else {
125
+ cmd .AddArguments (opts .Remote )
126
+ cmd .AddArguments (opts .Branch )
118
127
}
119
128
120
129
if opts .Timeout <= 0 {
@@ -131,6 +140,33 @@ func Push(repoPath, remote, branch string) error {
131
140
return err
132
141
}
133
142
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
+
134
170
// ResetHEAD resets HEAD to given revision or head of branch.
135
171
func ResetHEAD (repoPath string , hard bool , revision string ) error {
136
172
cmd := NewCommand ("reset" )
@@ -140,3 +176,11 @@ func ResetHEAD(repoPath string, hard bool, revision string) error {
140
176
_ , err := cmd .AddArguments (revision ).RunInDir (repoPath )
141
177
return err
142
178
}
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