55 "fmt"
66 "net/http"
77 "os"
8- "path/filepath"
98 "time"
109
1110 "github.com/cli/cli/v2/api"
@@ -19,17 +18,10 @@ import (
1918)
2019
2120func New (appVersion string ) * cmdutil.Factory {
22- var exe string
2321 f := & cmdutil.Factory {
24- Config : configFunc (), // No factory dependencies
25- Branch : branchFunc (), // No factory dependencies
26- Executable : func () string {
27- if exe != "" {
28- return exe
29- }
30- exe = executable ("gh" )
31- return exe
32- },
22+ Config : configFunc (), // No factory dependencies
23+ Branch : branchFunc (), // No factory dependencies
24+ ExecutableName : "gh" ,
3325 }
3426
3527 f .IOStreams = ioStreams (f ) // Depends on Config
@@ -121,52 +113,6 @@ func browserLauncher(f *cmdutil.Factory) string {
121113 return os .Getenv ("BROWSER" )
122114}
123115
124- // Finds the location of the executable for the current process as it's found in PATH, respecting symlinks.
125- // If the process couldn't determine its location, return fallbackName. If the executable wasn't found in
126- // PATH, return the absolute location to the program.
127- //
128- // The idea is that the result of this function is callable in the future and refers to the same
129- // installation of gh, even across upgrades. This is needed primarily for Homebrew, which installs software
130- // under a location such as `/usr/local/Cellar/gh/1.13.1/bin/gh` and symlinks it from `/usr/local/bin/gh`.
131- // When the version is upgraded, Homebrew will often delete older versions, but keep the symlink. Because of
132- // this, we want to refer to the `gh` binary as `/usr/local/bin/gh` and not as its internal Homebrew
133- // location.
134- //
135- // None of this would be needed if we could just refer to GitHub CLI as `gh`, i.e. without using an absolute
136- // path. However, for some reason Homebrew does not include `/usr/local/bin` in PATH when it invokes git
137- // commands to update its taps. If `gh` (no path) is being used as git credential helper, as set up by `gh
138- // auth login`, running `brew update` will print out authentication errors as git is unable to locate
139- // Homebrew-installed `gh`.
140- func executable (fallbackName string ) string {
141- exe , err := os .Executable ()
142- if err != nil {
143- return fallbackName
144- }
145-
146- base := filepath .Base (exe )
147- path := os .Getenv ("PATH" )
148- for _ , dir := range filepath .SplitList (path ) {
149- p , err := filepath .Abs (filepath .Join (dir , base ))
150- if err != nil {
151- continue
152- }
153- f , err := os .Stat (p )
154- if err != nil {
155- continue
156- }
157-
158- if p == exe {
159- return p
160- } else if f .Mode ()& os .ModeSymlink != 0 {
161- if t , err := os .Readlink (p ); err == nil && t == exe {
162- return p
163- }
164- }
165- }
166-
167- return exe
168- }
169-
170116func configFunc () func () (config.Config , error ) {
171117 var cachedConfig config.Config
172118 var configError error
0 commit comments