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

bug with .git file and aliases

From
Geoffrey Irving <irving@naml.us>
Date
Jul 20, 2009, 13:54 UTC
Message-ID
<7f9d599f0907200654q2e068e6aq3051c122f6596053@mail.gmail.com>
git 1.6.3.3 has a bug related to .git file support and aliases.
Specifically, if you make an alias for status and call it from a
subdirectory, git status chdirs into the true .git dir but then
chdir's back to the wrong place in order to run the lstats for status.
 The result is that git status thinks all files have disappeared.
Here's a self-contained test script:
    #!/bin/bash
    set -x
    # make a simple repository
    mkdir repo
    cd repo
    git init
    mkdir a
    echo content > a/b
    git add a/b
    git commit -m "a commit"
    # replace the gitdir with a gitfile
    mv .git ../repo.git
    echo gitdir: `pwd`.git > .git
    # normal git status works
    cd a
    git status
    # an alias for git status fails
    git config alias.st status
    git st
which produces output
top:tmp% ./bug
++ mkdir repo
++ cd repo
++ git init
Initialized empty Git repository in /Users/irving/tmp/tmp/repo/.git/
++ mkdir a
++ echo content
++ git add a/b
++ git commit -m 'a commit'
[master (root-commit) 6b07ec4] a commit
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 a/b
++ mv .git ../repo.git
+++ pwd
++ echo gitdir: /Users/irving/tmp/tmp/repo.git
++ cd a
++ git status
# On branch master
nothing to commit (working directory clean)
++ git config alias.st status
++ git st
# On branch master
# Changed but not updated:
#   (use "git add/rm <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#	deleted:    a/b
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#	b
no changes added to commit (use "git add" and/or "git commit -a")

.git file support also doesn't work on a repository with no commits (which is why the test script makes a commit normally before switching to a gitfile). However, I care about this second problem much less, and didn't notice it until I made the test script.

Finally, huge thanks to Lars for implementing this. I'm storing git working directories inside vesta, and symlink support is currently disabled. It's very pleasant to grep through the source and find that someone already fixed exactly my problem. :)

Geoffrey
Next: Santi Béjar
Message 1 of 13 in “bug with .git file and aliases”
  1. Geoffrey IrvingJul 20, 2009
  2. Santi BéjarJul 20, 2009
  3. Geoffrey IrvingJul 20, 2009
  4. Santi BéjarJul 20, 2009
  5. Geoffrey IrvingJul 20, 2009
  6. Jeff KingJul 20, 2009
  7. Geoffrey IrvingAug 10, 2009
  8. Johannes SchindelinAug 10, 2009
  9. Geoffrey IrvingAug 11, 2009
  10. Johannes SchindelinAug 11, 2009
  11. Michael J GruberAug 11, 2009
  12. Johannes SixtAug 11, 2009
  13. Michael J GruberAug 11, 2009

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.