File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -20,6 +20,16 @@ import (
2020 "github.com/mattn/go-isatty"
2121)
2222
23+ func isFlagSet (fs * flag.FlagSet , name string ) bool {
24+ var found bool
25+ fs .Visit (func (f * flag.Flag ) {
26+ if f .Name == name {
27+ found = true
28+ }
29+ })
30+ return found
31+ }
32+
2333func init () {
2434 usage := `
2535Examples:
@@ -96,7 +106,7 @@ Examples:
96106 }
97107 fmt .Println ("File: " + * fileFlag )
98108
99- if rootFlag == nil {
109+ if ! isFlagSet ( flagSet , "root" ) {
100110 checkError := func (err error ) {
101111 if err != nil {
102112 fmt .Println (err )
@@ -115,15 +125,16 @@ Examples:
115125 rel , err := filepath .Rel (strings .TrimSpace (string (topLevel )), absFile )
116126 checkError (err )
117127
118- * rootFlag = filepath .Dir (rel )
128+ relDir := filepath .Dir (rel )
129+ rootFlag = & relDir
119130 }
120131
121132 * rootFlag = filepath .Clean (* rootFlag )
122133 if strings .HasPrefix (* rootFlag , ".." ) {
123134 fmt .Println ("-root is outside the repository: " + * rootFlag )
124135 os .Exit (1 )
125136 }
126- if * rootFlag == "." {
137+ if * rootFlag == "." || * rootFlag == "/" {
127138 * rootFlag = ""
128139 }
129140 fmt .Println ("Root: " + * rootFlag )
You can’t perform that action at this time.
0 commit comments