@@ -257,50 +257,6 @@ func Push(ctx context.Context, repoPath string, opts PushOptions) error {
257
257
return err
258
258
}
259
259
260
- // CheckoutOptions options when heck out some branch
261
- type CheckoutOptions struct {
262
- Timeout time.Duration
263
- Branch string
264
- OldBranch string
265
- }
266
-
267
- // Checkout checkouts a branch
268
- func Checkout (repoPath string , opts CheckoutOptions ) error {
269
- cmd := NewCommand ("checkout" )
270
- if len (opts .OldBranch ) > 0 {
271
- cmd .AddArguments ("-b" )
272
- }
273
-
274
- if opts .Timeout <= 0 {
275
- opts .Timeout = - 1
276
- }
277
-
278
- cmd .AddArguments (opts .Branch )
279
-
280
- if len (opts .OldBranch ) > 0 {
281
- cmd .AddArguments (opts .OldBranch )
282
- }
283
-
284
- _ , err := cmd .RunInDirTimeout (opts .Timeout , repoPath )
285
- return err
286
- }
287
-
288
- // ResetHEAD resets HEAD to given revision or head of branch.
289
- func ResetHEAD (repoPath string , hard bool , revision string ) error {
290
- cmd := NewCommand ("reset" )
291
- if hard {
292
- cmd .AddArguments ("--hard" )
293
- }
294
- _ , err := cmd .AddArguments (revision ).RunInDir (repoPath )
295
- return err
296
- }
297
-
298
- // MoveFile moves a file to another file or directory.
299
- func MoveFile (repoPath , oldTreeName , newTreeName string ) error {
300
- _ , err := NewCommand ("mv" ).AddArguments (oldTreeName , newTreeName ).RunInDir (repoPath )
301
- return err
302
- }
303
-
304
260
// CountObject represents repository count objects report
305
261
type CountObject struct {
306
262
Count int64
@@ -325,14 +281,14 @@ const (
325
281
)
326
282
327
283
// CountObjects returns the results of git count-objects on the repoPath
328
- func CountObjects (repoPath string ) (* CountObject , error ) {
329
- return CountObjectsWithEnv (repoPath , nil )
284
+ func CountObjects (ctx context. Context , repoPath string ) (* CountObject , error ) {
285
+ return CountObjectsWithEnv (ctx , repoPath , nil )
330
286
}
331
287
332
288
// CountObjectsWithEnv returns the results of git count-objects on the repoPath with custom env setup
333
- func CountObjectsWithEnv (repoPath string , env []string ) (* CountObject , error ) {
334
- cmd := NewCommand ("count-objects" , "-v" )
335
- stdout , err := cmd .RunInDirWithEnv ( repoPath , env )
289
+ func CountObjectsWithEnv (ctx context. Context , repoPath string , env []string ) (* CountObject , error ) {
290
+ cmd := NewCommand (ctx , "count-objects" , "-v" )
291
+ stdout , _ , err := cmd .RunStdString ( & RunOpts { Dir : repoPath , Env : env } )
336
292
if err != nil {
337
293
return nil , err
338
294
}
@@ -346,21 +302,24 @@ func parseSize(objects string) *CountObject {
346
302
for _ , line := range strings .Split (objects , "\n " ) {
347
303
switch {
348
304
case strings .HasPrefix (line , statCount ):
349
- repoSize .Count = com . StrTo (line [7 :]). MustInt64 ( )
305
+ repoSize .Count , _ = strconv . ParseInt (line [7 :], 10 , 64 )
350
306
case strings .HasPrefix (line , statSize ):
351
- repoSize .Size = com .StrTo (line [6 :]).MustInt64 () * 1024
307
+ number , _ := strconv .ParseInt (line [6 :], 10 , 64 )
308
+ repoSize .Size = number * 1024
352
309
case strings .HasPrefix (line , statInpack ):
353
- repoSize .InPack = com . StrTo (line [9 :]). MustInt64 ( )
310
+ repoSize .InPack , _ = strconv . ParseInt (line [9 :], 10 , 64 )
354
311
case strings .HasPrefix (line , statPacks ):
355
- repoSize .Packs = com . StrTo (line [7 :]). MustInt64 ( )
312
+ repoSize .Packs , _ = strconv . ParseInt (line [7 :], 10 , 64 )
356
313
case strings .HasPrefix (line , statSizePack ):
357
- repoSize .SizePack = com .StrTo (line [11 :]).MustInt64 () * 1024
314
+ number , _ := strconv .ParseInt (line [11 :], 10 , 64 )
315
+ repoSize .SizePack = number * 1024
358
316
case strings .HasPrefix (line , statPrunePackage ):
359
- repoSize .PrunePack = com . StrTo (line [16 :]). MustInt64 ( )
317
+ repoSize .PrunePack , _ = strconv . ParseInt (line [16 :], 10 , 64 )
360
318
case strings .HasPrefix (line , statGarbage ):
361
- repoSize .Garbage = com . StrTo (line [9 :]). MustInt64 ( )
319
+ repoSize .Garbage , _ = strconv . ParseInt (line [9 :], 10 , 64 )
362
320
case strings .HasPrefix (line , statSizeGarbage ):
363
- repoSize .SizeGarbage = com .StrTo (line [14 :]).MustInt64 () * 1024
321
+ number , _ := strconv .ParseInt (line [14 :], 10 , 64 )
322
+ repoSize .SizeGarbage = number * 1024
364
323
}
365
324
}
366
325
return repoSize
0 commit comments