mislav / hub

A command-line tool that makes git easier to use with GitHub.
https://hub.github.com/
MIT License
22.83k stars 2.2k forks source link

Improve error message when git is not found #1030

Open xPaw opened 9 years ago

xPaw commented 9 years ago

My script looks like this:

cd /home/gfreeman/SteamLinux

# git commands to create a branch and push it, this part works as expected

echo "Creating pull request ($(pwd)) ($(git rev-parse -q --git-dir))"

hub pull-request -m "cool message" -b "master" -h "app-1000"

And the output of that is:

Creating pull request (/home/gfreeman/SteamLinux) (.git)
fatal: Not a git repository

Version:

git version 2.1.4
hub version 2.2.2

Script itself is outside of the git directory, so that could be cause it to use wrong directory?

mislav commented 9 years ago

This looks really weird, thanks for reporting. It looks like /home/gfreeman/SteamLinux/.git is a valid git repository. I can't imagine what would trip up hub. Can you try running different hub commands manually like hub ci-status or hub browse and see if they suffer from the same error?

xPaw commented 9 years ago

/home/gfreeman/SteamLinux/.git is indeed a valid repository.

I've tried to run the exact same script with same arguments under the same user manually, and it worked. For some reason when PHP executes it, hub command fails, despite being in the correct folder.

mislav commented 9 years ago

Must be something about the environment which PHP initializes for its sub-processes, but I can't guess without access to your machine. Can you inspect environment variables via env, particulary ones whose name mentions "GIT"?

xPaw commented 9 years ago

The only variables when PHP runs env are USER, HOME and PWD.

mislav commented 9 years ago

I have no idea why it doesn't work within PHP. Basically, hub internally calls git rev-parse -q --git-dir to check if the current directory is in a git repo.

xPaw commented 9 years ago

As you can see in the script output, git rev-parse -q --git-dir actually finds the .git repository, and the git commit/push commands do work, it's the hub that fails.

mislav commented 8 years ago

@xPaw It's been a long time since you reported this issue, and I have received no similar reports. Did this remain a problem for you? Do you think we can shrug this off and close this? I'm sorry I couldn't help. Thanks

xPaw commented 7 years ago

Well, that's fun. I moved to a completely new server (with new OS installation), and I can still reproduce this issue.

git version 2.1.4
hub version 2.3.0-pre8

EDIT: Doing hub status prints exec: "git": command not found. Adding export PATH=/usr/bin before running hub fixes it.

So this leads to two points:

  1. Why git works, but hub executing git does not?
  2. hub needs to correctly displays when git is not found. This works for aliased git commands, but not for commands hub implements.
mislav commented 7 years ago

I'm sorry this is still giving you problems.

1. Why git works, but hub executing git does not?

I would guess that this happened because the PATH for the hub process didn't have /usr/bin before you manually added it. It is the responsibility of the parent process to ensure that PATH is well formed. I think your workaround is fine and that this is not indicative of a bug in hub.

2. hub needs to correctly displays when git is not found. This works for aliased git commands, but not for commands hub implements.

Can you explain more about this? Which is the command that you run with hub that has a non-friendly error message, what does that message say, and what should it say instead?

xPaw commented 7 years ago

Can you explain more about this? Which is the command that you run with hub that has a non-friendly error message, what does that message say, and what should it say instead?

I would expect a message like hub status gave me: "git": command not found instead of saying fatal: Not a git repository. The command that produces this message is hub pull-request.

mislav commented 7 years ago

@xPaw Thanks; I'll see what I can do about improving this error message.

jcsnider commented 6 years ago

Same use case and same error calling this within php. His solution of including export PATH=/usr/bin before hub pull-request also solved this for me. I can confirm that this remains a bug, albeit very low priority given the easy workaround.

Thanks for this incredible library!