mroth / scmpuff

:1234: Numeric file shortcuts for common git commands
https://mroth.github.io/scmpuff/
MIT License
383 stars 22 forks source link

no such file or directory: ../../usr/local/bin/git #61

Closed tekumara closed 2 years ago

tekumara commented 2 years ago

When in the directory /tmp/setup on the master branch:

$ git checkout testing-image
(eval):1: no such file or directory: ../../usr/local/bin/git
$ which -a git
git () {
    case $1 in
        (commit | blame | log | rebase | merge) eval "$(scmpuff expand -- "$SCMPUFF_GIT_CMD" "$@")" ;;
        (checkout | diff | rm | reset) eval "$(scmpuff expand --relative -- "$SCMPUFF_GIT_CMD" "$@")" ;;
        (add) eval "$(scmpuff expand -- "$SCMPUFF_GIT_CMD" "$@")"
            scmpuff_status ;;
        (*) "$SCMPUFF_GIT_CMD" "$@" ;;
    esac
}
/usr/local/bin/git
/usr/bin/git

This works without error:

/usr/local/bin/git checkout testing-image
mroth commented 2 years ago

Hmm. Strange. Thanks for the bug report. Some questions:

  1. What is your operating system and version?
  2. What is your shell and version?
  3. Does this only happen when you are in the /tmp/setup directory, or does it occur with all repositories?
  4. If sounds like $SCMPUFF_GIT_CMD is somehow not properly set. If you get in that state, what does echo $SCMPUFF_GIT_CMD output? (From looking at your other output, I'm guessing it will return ../../usr/local/bin/git -- which would be indicative of a problem being a relative path rather than absolute -- but I want to confirm this before debugging further.)

Thanks!

tekumara commented 2 years ago

Thanks for taking a look!

  1. macOS Big Sur 11.6.1 (20G224)
  2. $ zsh --version
    zsh 5.8 (x86_64-apple-darwin20.1.0) 
  3. Only in subdirs of /tmp but with any repo
  4. $ echo $SCMPUFF_GIT_CMD
    /usr/local/bin/git
mroth commented 2 years ago

Okay, I think I've tracked this down. It's quite weird.

  1. Under the hood the scmpuff's shell wrapper for git checkout is evaling a command which uses scmpuff expand --relative. scmpuff expand --relative takes absolute paths and converts them to relative. As we can see below, it's doing this for the $SCMPUFF_GIT_CMD as well when it is an absolute path, which is probably undesired.
$ export e1=~/src/scmpuff/scripts/benchmark.sh

$ scmpuff expand  -- git blah 1 
git blah    /Users/mroth/src/scmpuff/scripts/benchmark.sh

$ scmpuff expand --relative -- git blah 1
git blah    scripts/benchmark.sh

$ scmpuff expand --relative  -- /usr/bin/git blah 1
../../../../usr/bin/git blah    scripts/benchmark

I suspect since $SCMPUFF_GIT_CMD was simply git in the integration test environment I never noticed this?

Now, normally this wouldn't cause execution problems, but...

  1. /tmp on macOS is actually /private/tmp, in a way that confuses filepath.Rel() in Go. See #31 and #11 for additional context. Normally this isn't an issue (the messy paths resolve fine for files), but seems to be causing an issue for finding the git binary here. I believe the switch to scmpuff exec as default in #49 may make this irrelevant when released, but I'd like to fix the underlying issue anyhow.