Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to use git when cwd is nonexistent directory #472

Open
gausie opened this issue Jan 27, 2014 · 9 comments
Open

Unable to use git when cwd is nonexistent directory #472

gausie opened this issue Jan 27, 2014 · 9 comments
Labels

Comments

@gausie
Copy link

gausie commented Jan 27, 2014

I'm now getting

/usr/local/bin/hub:1227:in `pwd': No such file or directory - getcwd (Errno::ENOENT)
    from /usr/local/bin/hub:1227:in `<module:Context>'
    from /usr/local/bin/hub:765:in `<module:Hub>'
    from /usr/local/bin/hub:764:in `<main>'

for whatever I try to do with Git.

@mislav
Copy link
Owner

mislav commented Jan 27, 2014

Checked out an old commit of which repository? What is the output of pwd (in the shell) at the time that you're getting the error from hub? Does this happen in any directory on your machine or just one project?

@mislav
Copy link
Owner

mislav commented Feb 2, 2014

Ping! Need more info on this

@mislav
Copy link
Owner

mislav commented Feb 20, 2014

Closing due to lack of info

@mislav mislav closed this as completed Feb 20, 2014
@markstos
Copy link

markstos commented Aug 4, 2014

I'm getting the same error now, even for the most basic commands:

$ hub --version
/usr/local/bin/hub:1305:in `pwd': No such file or directory - getcwd (Errno::ENOENT)
        from /usr/local/bin/hub:1305:in `<module:Context>'
        from /usr/local/bin/hub:834:in `<module:Hub>'
        from /usr/local/bin/hub:833:in `<main>'

Here's what I know about how to reproduce it:

  • I created a directory and put some files in it. The files had been added with git add, and then a new commit created touching only the files in this directory.
  • The first time it happened, I was in the new directory and tried this:
$ git whatchanged origin/develop..develop
/usr/local/bin/hub:1305:in `pwd': No such file or directory - getcwd (Errno::ENOENT)
        from /usr/local/bin/hub:1305:in `<module:Context>'
        from /usr/local/bin/hub:834:in `<module:Hub>'
        from /usr/local/bin/hub:833:in `<main>'

If I cd up out of the directory which does not exist upstream, then hub --version starts working again:

$ hub --version
git version 2.0.4
hub version 1.12.0-10-g67728bc

Here's a reduced test case to trigger it, although I'm not sure how similar it is to case I ran into:

mkdir git-test
cd git-test/

Now in another terminal window, rm -rf the git-test created above. Then, switch back to the original window, in which the shell is running in a directory which no longer exists:

$ hub --version
/usr/local/bin/hub:1305:in `pwd': No such file or directory - getcwd (Errno::ENOENT)
        from /usr/local/bin/hub:1305:in `<module:Context>'
        from /usr/local/bin/hub:834:in `<module:Hub>'
        from /usr/local/bin/hub:833:in `<main>'

Boom goes the dynamite.

It could be that people get into this situation in more normal usage scenarios perhaps because git pull --rebase changes inode values. (I'm not sure that it goes, just guessing). So even though the directory the shell is in may in fact exist (as it did my original case), bash is now confused.

@mislav
Copy link
Owner

mislav commented Aug 4, 2014

Oh, so you end up in a directory which doesn't exist (gets deleted through git checkout). I get it now. Nasty problem—I'll see what can be done.

@mislav mislav reopened this Aug 4, 2014
@mislav mislav added the bug label Aug 4, 2014
@mislav mislav changed the title Checked out an old commit and now getting an error message for any command Unable to use git when cwd is nonexistent directory Aug 4, 2014
@markstos
Copy link

markstos commented Aug 5, 2014

Here's the more interesting case than a purely missing directory: This corresponds to a changed-inode case, which I think I ran into as part of a rebase workflow:

  • create a temporary directory and cd into it
  • In another window, delete the temporary directory, but then recreate it with the same name.

hub is now operating in a directory that actually exists but will fail with "no such file or directory". In the real-life case, the directory may be re-populated with files and look much as it did before.

@markstos
Copy link

markstos commented Aug 5, 2014

I looked at other ways to get the equivalent of pwd when the inode has changed, but couldn't find any. It seems the best that can be done is to check to see if an error is thrown by pwd and provide a more helpful diagnostic in that case:

The directory you are running hub in either does not exist or the inode has changed. If the directory actually exists, try moving out of the directory and back into it, and running hub again.

@gtchaos
Copy link

gtchaos commented Oct 7, 2014

😄

@mslinn
Copy link

mslinn commented Dec 22, 2016

This worked for me:

hash -r

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants