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

git rebase exec make -C in worktree confuses repo root dir

From
DMDavid Moberg <kaddkaka@gmail.com>
Date
Oct 14, 2024, 20:46 UTC
Message-ID
<CAL2+Miudq0UXAb=R24v+ftZVkHy2We1CFsFAt__tCYMWtCfOow@mail.gmail.com>

Hi, I tried to minimize this but I haven't been able to come to a much smaller example.

/David "kaddkaka" Moberg
What did you do before the bug happened? (Steps to reproduce your issue)

When doing `git rebase --exec` in a "secondary" worktree, it seems that there is confusion about where the repo root dir is. This sequence of commands can be run to reproduce:

  mktemp -d /tmp/git_bugreport_rebase_exec_worktree_root.XXXXXX
  cd /tmp/git_bugreport_rebase_exec_worktree_root.*
  mkdir repo
  cd repo/
  mkdir dir
  echo -e 'lint:' > dir/Makefile
  echo -e '\tgit rev-parse --show-toplevel' >> dir/Makefile
  echo -e '\tgit grep "banana" -- "$$BANANA"' >> dir/Makefile
  git init
  git add dir
  git commit -m"Intial commit"
  git worktree add ../repo2
  cd ../repo2/
  BANANA=$PWD GIT_EDITOR='sed -i "1s/noop/exec make -C dir\/ lint/"'
git rebase -i HEAD
What did you expect to happen? (Expected behavior)
1. This command should return the worktree toplevel, not a subdirectory
  $ git rev-parse --show-toplevel
  /tmp/tmp.DUUAVQCIKe/repo2
2. And the git grep command should return the match from dir/Makefile,
not Fatal Error
  $ git grep banana
  Makefile:       git grep "banana" -- "$$BANANA"
What happened instead? (Actual behavior)
1. --show-toplevel reports a subdirectory instead of toplevel:
  $ git rev-parse --show-toplevel
  /tmp/tmp.DUUAVQCIKe/repo2/dir
2. git grep complains that the pathspec is outside the repository with
fatal error:
  $ git grep "banana" -- "$BANANA"
  fatal: /tmp/tmp.DUUAVQCIKe/repo2: '/tmp/tmp.DUUAVQCIKe/repo2' is
outside repository at '/tmp/tmp.DUUAVQCIKe/repo2/dir'
  make: *** [Makefile:3: lint] Error 128
  make: Leaving directory '/tmp/tmp.DUUAVQCIKe/repo2/dir'
  warning: execution failed: make -C dir/ lint
What's different between what you expected and what actually happened?
See above.

[System Info] git version: git version 2.43.0 cpu: x86_64 no commit associated with this build sizeof-long: 8 sizeof-size_t: 8 shell-path: /bin/sh uname: Linux 6.8.0-45-generic #45-Ubuntu SMP PREEMPT_DYNAMIC Fri Aug 30 12:02:04 UTC 2024 x86_64 compiler info: gnuc: 13.2 libc info: glibc: 2.39 $SHELL (typically, interactive shell): /usr/bin/bash

[Enabled Hooks]
Next: Taylor Blau
Message 1 of 11 in “git rebase exec make -C in worktree confuses repo root dir”
  1. David MobergOct 14, 2024
  2. Taylor BlauOct 14, 2024
  3. David MobergOct 14, 2024
  4. Eric SunshineOct 15, 2024
  5. David MobergOct 15, 2024
  6. Eric SunshineOct 15, 2024
  7. Phillip WoodOct 16, 2024
  8. Taylor BlauOct 16, 2024
  9. Elijah NewrenOct 17, 2024
  10. Eric SunshineOct 16, 2024
  11. phillip.wood123@gmail.comNov 5, 2024

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.