git/list[1] front-page[2] threads[3] people[4] search[5] about
 

git clone doesn't cleanup on failure when getcwd fails

From
SNSpencer Nelson <s@spenczar.com>
Date
Mar 18, 2015, 18:03 UTC
Message-ID
<etPan.5509bdf2.7a1ae87d.1766@ttvadmins-MacBook-Pro.local>
 
If you’re in a shell in a directory which no longer exists (because, say, another terminal removed it), then getcwd() will fail, at least on OS X Yosemite 10.10.2. In this case, git clone will fail. That’s totally reasonable.  
If you invoke git clone with the git clone <repo> <dir> syntax, then <dir> will be created, but it will be empty.
This was unexpected - I would think the failure case shouldn’t leave this empty directory, but should instead clean up after itself.
I’m not alone: golang’s go get command for installing third-party packages performs a `git clone <repo> <dir>` only if <dir> does not already exist - if it does exist, then go believes that the package is already installed, and so does nothing. So, if you call go get from within a directory which no longer exists, git will create the empty directory, putting go get into a bad state.
Concrete example:

Make a dummy repo in /tmp/somerepo: tty1: $ cd /tmp $ git init somerepo

In another tty, make a /tmp/poof and enter it tty2: $ mkdir /tmp/poof $ cd /tmp/poof

In the first tty, delete /tmp/poof tty1: $ rmdir /tmp/poof

Finally, in the second tty, clone: tty2: $ git clone /tmp/somerepo /tmp/newcopy fatal: Could not get current working directory: No such file or directory $ ls /tmp/newcopy && echo "yes, it exists" yes, it exists

My version details:

$ git version git version 2.3.2

$ uname -a Darwin mbp.local 14.1.0 Darwin Kernel Version 14.1.0: Thu Feb 26 19:26:47 PST 2015; root:xnu-2782.10.73~1/RELEASE_X86_64 x86_64

Next: Jeff King
Message 1 of 3 in “git clone doesn't cleanup on failure when getcwd fails”
  1. Spencer NelsonMar 18, 2015
  2. clone: initialize atexit cleanup handler earlierJeff King, Mar 18, 2015
  3. clone: drop period from end of die_errno messageJeff King, Mar 18, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.