@@ -36,30 +36,35 @@ func ActionChanges(opts ChangeOpts) carapace.Action {
36
36
if root , err := rootDir (c ); err != nil {
37
37
return carapace .ActionMessage (err .Error ())
38
38
} else {
39
+ evaluatedDir , err := filepath .EvalSymlinks (c .Dir )
40
+ if err != nil {
41
+ return carapace .ActionMessage (err .Error ())
42
+ }
43
+
39
44
untracked := make ([]string , 0 )
40
45
for _ , line := range strings .Split (string (output ), "\n " ) {
41
- if len (line ) > 3 {
42
- if (opts .Staged && line [1 ] == ' ' ) ||
43
- (opts .Unstaged && line [1 ] != ' ' && line [1 ] != '!' ) ||
44
- (opts .Ignored && line [1 ] == '!' ) {
45
- path := line [3 :]
46
- if splitted := strings .SplitN (path , " -> " , 2 ); len (splitted ) > 1 { // renamed
47
- path = splitted [1 ]
48
- }
46
+ switch {
47
+ case len (line ) < 4 :
48
+ // skip
49
+ case opts .Staged && line [1 ] == ' ' ,
50
+ opts .Unstaged && line [1 ] != ' ' && line [1 ] != '!' ,
51
+ opts .Ignored && line [1 ] == '!' :
52
+
53
+ path := line [3 :]
54
+ if splitted := strings .SplitN (path , " -> " , 2 ); len (splitted ) > 1 { // renamed
55
+ path = splitted [1 ]
56
+ }
57
+
58
+ relativePath , err := filepath .Rel (evaluatedDir , root + "/" + path )
59
+ if err != nil {
60
+ return carapace .ActionMessage (err .Error ())
61
+ }
49
62
50
- evaluatedDir , err := filepath .EvalSymlinks (c .Dir )
51
- if err != nil {
52
- return carapace .ActionMessage (err .Error ())
53
- }
54
- if relativePath , err := filepath .Rel (evaluatedDir , root + "/" + path ); err != nil {
55
- return carapace .ActionMessage (err .Error ())
56
- } else {
57
- if status := line [:2 ]; strings .Contains (status , "D" ) { // deleted
58
- untracked = append (untracked , relativePath , status , style .ForPathExt (relativePath , c ))
59
- } else {
60
- untracked = append (untracked , relativePath , status , style .ForPath (relativePath , c ))
61
- }
62
- }
63
+ switch status := line [:2 ]; {
64
+ case strings .Contains (status , "D" ): // deleted
65
+ untracked = append (untracked , relativePath , status , style .ForPathExt (relativePath , c ))
66
+ default :
67
+ untracked = append (untracked , relativePath , status , style .ForPath (relativePath , c ))
63
68
}
64
69
}
65
70
}
0 commit comments