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

[BUG] Git 2.39.0+ Git.pm ignores Directory=> argument for bare repos

From
HLHank Leininger <hlein@korelogic.com>
Date
Jul 30, 2023, 20:42 UTC
Message-ID
<20230730140659.0cc15491-00d2-4e58-af57-aaf5e74b5827@korelogic.com>

Recent git versions (2.39.0 through 2.41.0) Git.pm seems to forget its Directory argument for bare repos. Initial creation of a Git->repository object will succeed, but subsequent $repo->command() fails unless the repo is in pwd or is set in the GIT_DIR environment argument.

  patsy@ultron ~/tmp/repo-test $ git init --bare test1.git
  Initialized empty Git repository in /home/patsy/tmp/repo-test/test1.git/
  # success with 2.38.4
  patsy@ultron ~/tmp/repo-test $ git --version
  git version 2.38.4
  patsy@ultron ~/tmp/repo-test $ perl -MGit -e 'my $repo = Git->repository(Directory=>"/home/patsy/tmp/repo-test/test1.git/")||die "git open failed: $!\n"; $repo->command("rev-list", "--all", "-1"); print "rev-list succeeded\n"'
  rev-list succeeded
  # fail with 2.41.0
  patsy@ultron ~/tmp/repo-test $ git --version
  git version 2.41.0
  patsy@ultron ~/tmp/repo-test $ perl -MGit -e 'my $repo =
  Git->repository(Directory=>"/home/patsy/tmp/repo-test/test1.git/")||die "git open failed: $!\n"; $repo->command("rev-list", "--all", "-1"); print "rev-list succeeded\n"'
  fatal: not a git repository: '/home/patsy/tmp/repo-test'
  rev-list --all -1: command returned error: 128
  # success with 2.41.0 after cd
  patsy@ultron ~/tmp/repo-test $ cd test1.git/
  patsy@ultron ~/tmp/repo-test/test1.git $ perl -MGit -e 'my $repo = Git->repository(Directory=>"/home/patsy/tmp/repo-test/test1.git/")||die "git open failed: $!\n"; $repo->command("rev-list", "--all", "-1"); print "rev-list succeeded\n"'
  rev-list succeeded
  # success with 2.41.0 with GIT_DIR= set
  patsy@ultron ~/tmp/repo-test $
  GIT_DIR=/home/patsy/tmp/repo-test/test1.git/ perl -MGit -e 'my $repo = Git->repository(Directory=>"/home/patsy/tmp/repo-test/test1.git/")||die "git open failed: $!\n"; $repo->command("rev-list", "--all", "-1"); print "rev-list succeeded\n"'
  rev-list succeeded
It seems to be only bare repos that are a problem:
  # success with 2.41.0 for a non-bare repo
  patsy@ultron ~/tmp/repo-test $ git --version
  git version 2.41.0
  patsy@ultron ~/tmp/repo-test $ git init test2
  Initialized empty Git repository in /home/patsy/tmp/repo-test/test2/.git/
  patsy@ultron ~/tmp/repo-test $ perl -MGit -e 'my $repo = Git->repository(Directory=>"/home/patsy/tmp/repo-test/test2")||die "git open failed: $!\n"; $repo->command("rev-list", "--all", "-1"); print "rev-list succeeded\n"'
  rev-list succeeded

When stracing both, I can see that Git.pm does an initial execve of git rev-parse --is-bare-repository --git-dir, and it *does* cd prior to that. But running the specified command is done in a new child which does not chdir first. For non-bare repos, the child executing the command does chdir.

Thanks,
-- 
Hank Leininger <hlein@korelogic.com>
9606 3BF9 B593 4CBC E31A  A384 6200 F6E3 781E 3DD7
Next: Junio C Hamano
Message 1 of 2 in “[BUG] Git 2.39.0+ Git.pm ignores Directory=> argument for bare repos”
  1. Hank LeiningerJul 30, 2023
  2. Junio C HamanoJul 31, 2023

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.