@@ -15,6 +15,7 @@ import (
1515 "io"
1616 "net/http"
1717 "os"
18+ "os/exec"
1819 "path/filepath"
1920 "runtime"
2021 "strconv"
@@ -91,6 +92,9 @@ func CheckAndUpdate(config *core.Configuration, updatesEnabled, updateCommand, f
9192 // Clean out any old ones
9293 clean (config , updateCommand )
9394
95+ // Warn if the binary in PATH isn't the one we just updated.
96+ warnIfNotInPath (config )
97+
9498 // Now run the new one.
9599 core .ReturnToInitialWorkingDir ()
96100 args := filterArgs (forceUpdate , append ([]string {newPlease }, os .Args [1 :]... ))
@@ -406,6 +410,28 @@ func writeTarFile(hdr *tar.Header, r io.Reader, destination string) error {
406410 return err
407411}
408412
413+ // warnIfNotInPath emits a warning if the binary found via PATH is not the one we just updated.
414+ // This catches the common case where e.g. a Homebrew-installed plz shadows the one in ~/.please.
415+ func warnIfNotInPath (config * core.Configuration ) {
416+ name := filepath .Base (os .Args [0 ])
417+ pathBinary , err := exec .LookPath (name )
418+ if err != nil {
419+ return
420+ }
421+ pathBinary , _ = filepath .Abs (pathBinary )
422+ if resolved , err := filepath .EvalSymlinks (pathBinary ); err == nil {
423+ pathBinary = resolved
424+ }
425+ location , _ := filepath .Abs (config .Please .Location )
426+ if ! strings .HasPrefix (pathBinary , location + string (filepath .Separator )) && pathBinary != location {
427+ log .Warning ("Updated %s in %s but %q in your PATH resolves to %s" ,
428+ config .Please .Version .VersionString (), location , name , pathBinary )
429+ log .Warning ("To use the updated version, add %s to your PATH ahead of %s:" ,
430+ location , filepath .Dir (pathBinary ))
431+ log .Warning (" export PATH=%s:$PATH" , location )
432+ }
433+ }
434+
409435// filterArgs filters out the --force update if forced updates were specified.
410436// This is important so that we don't end up in a loop of repeatedly forcing re-downloads.
411437func filterArgs (forceUpdate bool , args []string ) []string {
0 commit comments