@@ -14,10 +14,14 @@ import (
14
14
"github.com/G-Node/gin-cli/git/shell"
15
15
)
16
16
17
+ // The following appears in the 'note' field when a file is added to git
18
+ // instead of annex
19
+ const addedToGitNote = "non-large file; adding content to git repository"
20
+
17
21
// Git annex commands
18
22
19
- // Determine if json or normal command is used
20
- var JsonBool bool = true
23
+ // RawMode disables -- json output for annex commands
24
+ var RawMode bool = false
21
25
22
26
// Types (private)
23
27
type annexAction struct {
@@ -262,11 +266,11 @@ func AnnexPush(paths []string, remote string, pushchan chan<- RepoFileStatus) {
262
266
}
263
267
264
268
var args []string
265
- if JsonBool {
266
- args = []string {"copy" , "--json-progress" , fmt .Sprintf ("--to=%s" , remote )}
267
- } else {
268
- args = []string {"copy" , "--verbose" , fmt .Sprintf ("--to=%s" , remote )}
269
+ outflag := "--json-progress"
270
+ if RawMode {
271
+ outflag = "--verbose"
269
272
}
273
+ args = []string {"copy" , outflag , fmt .Sprintf ("--to=%s" , remote )}
270
274
if len (paths ) == 0 {
271
275
paths = []string {"--all" }
272
276
}
@@ -299,7 +303,7 @@ func AnnexPush(paths []string, remote string, pushchan chan<- RepoFileStatus) {
299
303
// skip empty lines
300
304
continue
301
305
}
302
- if ! JsonBool {
306
+ if RawMode {
303
307
status .RawOutput = string (outline )
304
308
lineInput := cmd .Args
305
309
input := strings .Join (lineInput , " " )
@@ -393,7 +397,7 @@ func baseAnnexGet(cmdargs []string, getchan chan<- RepoFileStatus) {
393
397
continue
394
398
}
395
399
396
- if ! JsonBool {
400
+ if RawMode {
397
401
lineInput := cmd .Args
398
402
input := strings .Join (lineInput , " " )
399
403
status .RawInput = input
@@ -453,12 +457,11 @@ func baseAnnexGet(cmdargs []string, getchan chan<- RepoFileStatus) {
453
457
// (git annex get)
454
458
func AnnexGet (filepaths []string , getchan chan <- RepoFileStatus ) {
455
459
defer close (getchan )
456
- var cmdargs []string
457
- if JsonBool {
458
- cmdargs = append ([]string {"get" , "--json-progress" }, filepaths ... )
459
- } else {
460
- cmdargs = append ([]string {"get" }, filepaths ... )
460
+ cmdargs := []string {"get" }
461
+ if ! RawMode {
462
+ cmdargs = append (cmdargs , "--json-progress" )
461
463
}
464
+ cmdargs = append (cmdargs , filepaths ... )
462
465
baseAnnexGet (cmdargs , getchan )
463
466
}
464
467
@@ -477,12 +480,12 @@ func AnnexGetKey(key string, getchan chan<- RepoFileStatus) {
477
480
// (git annex drop)
478
481
func AnnexDrop (filepaths []string , dropchan chan <- RepoFileStatus ) {
479
482
defer close (dropchan )
480
- var cmdargs []string
481
- if JsonBool {
482
- cmdargs = append ([]string {"drop" , "--json" }, filepaths ... )
483
- } else {
484
- cmdargs = append ([]string {"drop" }, filepaths ... )
483
+ cmdargs := []string {"drop" }
484
+ if ! RawMode {
485
+ cmdargs = append (cmdargs , "--json" )
485
486
}
487
+ cmdargs = append (cmdargs , filepaths ... )
488
+
486
489
cmd := AnnexCommand (cmdargs ... )
487
490
err := cmd .Start ()
488
491
if err != nil {
@@ -508,7 +511,7 @@ func AnnexDrop(filepaths []string, dropchan chan<- RepoFileStatus) {
508
511
continue
509
512
}
510
513
511
- if ! JsonBool {
514
+ if RawMode {
512
515
lineInput := cmd .Args
513
516
input := strings .Join (lineInput , " " )
514
517
status .RawInput = input
@@ -673,11 +676,9 @@ func AnnexLock(filepaths []string, lockchan chan<- RepoFileStatus) {
673
676
log .Write ("No paths to lock. Nothing to do." )
674
677
return
675
678
}
676
- var cmdargs []string
677
- if JsonBool {
678
- cmdargs = []string {"lock" , "--json-error-messages" }
679
- } else {
680
- cmdargs = []string {"lock" }
679
+ cmdargs := []string {"lock" }
680
+ if ! RawMode {
681
+ cmdargs = append (cmdargs , "--json-error-messages" )
681
682
}
682
683
683
684
cmdargs = append (cmdargs , filepaths ... )
@@ -700,7 +701,7 @@ func AnnexLock(filepaths []string, lockchan chan<- RepoFileStatus) {
700
701
// Empty line output. Ignore
701
702
continue
702
703
}
703
- if ! JsonBool {
704
+ if RawMode {
704
705
status .RawOutput = string (outline )
705
706
lineInput := cmd .Args
706
707
input := strings .Join (lineInput , " " )
@@ -756,11 +757,9 @@ func AnnexLock(filepaths []string, lockchan chan<- RepoFileStatus) {
756
757
// (git annex unlock)
757
758
func AnnexUnlock (filepaths []string , unlockchan chan <- RepoFileStatus ) {
758
759
defer close (unlockchan )
759
- var cmdargs []string
760
- if JsonBool {
761
- cmdargs = []string {"unlock" , "--json" }
762
- } else {
763
- cmdargs = []string {"unlock" }
760
+ cmdargs := []string {"unlock" }
761
+ if ! RawMode {
762
+ cmdargs = append (cmdargs , "--json" )
764
763
}
765
764
cmdargs = append (cmdargs , filepaths ... )
766
765
cmd := AnnexCommand (cmdargs ... )
@@ -781,7 +780,7 @@ func AnnexUnlock(filepaths []string, unlockchan chan<- RepoFileStatus) {
781
780
// Empty line output. Ignore
782
781
continue
783
782
}
784
- if ! JsonBool {
783
+ if RawMode {
785
784
lineInput := cmd .Args
786
785
input := strings .Join (lineInput , " " )
787
786
status .RawInput = input
@@ -930,11 +929,9 @@ func AnnexAdd(filepaths []string, addchan chan<- RepoFileStatus) {
930
929
log .Write ("No paths to add to annex. Nothing to do." )
931
930
return
932
931
}
933
- var cmdargs []string
934
- if JsonBool {
935
- cmdargs = []string {"add" , "--json" }
936
- } else {
937
- cmdargs = []string {"add" }
932
+ cmdargs := []string {"add" }
933
+ if ! RawMode {
934
+ cmdargs = append (cmdargs , "--json" )
938
935
}
939
936
exclargs := annexExclArgs ()
940
937
if len (exclargs ) > 0 {
@@ -954,21 +951,21 @@ func AnnexAdd(filepaths []string, addchan chan<- RepoFileStatus) {
954
951
var status RepoFileStatus
955
952
var addresult annexAction
956
953
// NOTE Can differentiate "git" and "annex" files from note in JSON struct
957
- status .State = "Adding"
958
954
var filenames []string
959
955
for rerr = nil ; rerr == nil ; outline , rerr = cmd .OutReader .ReadBytes ('\n' ) {
960
956
if len (outline ) == 0 {
961
957
// Empty line output. Ignore
962
958
continue
963
959
}
964
- if ! JsonBool {
960
+ if RawMode {
965
961
status .RawOutput = string (outline )
966
962
lineInput := cmd .Args
967
963
input := strings .Join (lineInput , " " )
968
964
status .RawInput = input
969
965
addchan <- status
970
966
continue
971
967
}
968
+ addresult = annexAction {} // clear existing result
972
969
err := json .Unmarshal (outline , & addresult )
973
970
if err != nil || addresult .Command == "" {
974
971
// Couldn't parse output
@@ -983,7 +980,13 @@ func AnnexAdd(filepaths []string, addchan chan<- RepoFileStatus) {
983
980
status .RawInput = input
984
981
status .RawOutput = string (outline )
985
982
if addresult .Success {
986
- log .Write ("%s added to annex" , addresult .File )
983
+ if addresult .Note == addedToGitNote {
984
+ status .State = "Added to git"
985
+ log .Write ("%s added to git" , addresult .File )
986
+ } else {
987
+ status .State = "Added to annex"
988
+ log .Write ("%s added to annex" , addresult .File )
989
+ }
987
990
status .Err = nil
988
991
filenames = append (filenames , status .FileName )
989
992
} else {
0 commit comments