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

Re: fatal: unable to create '.git/index': File exists

From
Fredrik Kuivinen <frekui@gmail.com>
Date
Jan 6, 2007, 09:24 UTC
Message-ID
<4c8ef70701060124u3fa1dddfp5347a006c4ebb13d@mail.gmail.com>
In-Reply-To
<Pine.LNX.4.63.0701052115161.22628@wbgn013.biozentrum.uni-wuerzburg.de>
On 1/5/07, Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:
Show 17 quoted lines
> Hi,
>
> On Fri, 5 Jan 2007, Len Brown wrote:
>
> > I kicked off a pull.
> > Realized I was on the wrong branch
> > and immediately did a ^C
> >
> > Now I can't change branches:
> >
> > # git checkout release
> > fatal: unable to create '.git/index': File exists
>
> This usually means that .git/index.lock exists. Try removing that file.
>
> However, it _should_ be removed by the atexit() handler, methinks. I have
> no idea why it does not.

We will get SIGINT when the user hits ^C so I don't think the atexit handler will run. However, we also install a signal handler for SIGINT which removes the lock file, so I don't really see how it can be left around...

There is a small race condition between open and signal as we do
    fd = open(lk->filename, O_RDWR | O_CREAT | O_EXCL, 0666);
    ...
    signal(SIGINT, remove_lock_file_on_signal);
    atexit(remove_lock_file);

in lock_file:lockfile.c. But I think it is very improbable that the user hits ^C between "open" and "signal". It might be worth fixing though.

Are there any other signals we might get when the user hits ^C? SIGPIPE?
- Fredrik
Previous: Johannes SchindelinNext: Len Brown
Message 4 of 5 in “fatal: unable to create '.git/index': File exists”
  1. Len BrownJan 5, 2007
  2. ManuJan 5, 2007
  3. Johannes SchindelinJan 5, 2007
  4. Fredrik KuivinenJan 6, 2007
  5. Len BrownJan 6, 2007

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.