question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unresolvable reference when .git is a file (git worktree support)

See original GitHub issue

Git will sometimes configure the .git file to be a file, instead of a directory. This file has contents similar to:

gitdir: /home/awwright/repo.git/worktrees/work

This happens, among other cases, when a working tree is created with git-worktree. Here is a script showing the difference in behavior:

NAME=$(uuidgen).test
mkdir $NAME
pushd $NAME
git clone https://github.com/isomorphic-git/test.empty repo
git --git-dir=repo/.git worktree add work master

echo '{"dependencies":{"isomorphic-git":"0.55.0"}}' > package.json
yarn install

pushd work
echo
echo 'Git works:'
git log -1
echo
echo 'isomorphic-git bails:'
node -e 'require("isomorphic-git").log({depth:1, fs:require("fs"), dir:process.cwd(), ref:"HEAD"}).then(console.log, console.error);'
popd

pushd repo
echo
echo 'but it works in the default working tree:'
node -e 'require("isomorphic-git").log({depth:1, fs:require("fs"), dir:process.cwd(), ref:"HEAD"}).then(console.log, console.error);'
popd
popd

I would expect both calls to work, but only the second one does, with the first producing an error:

GitError [ResolveRefError]: Could not resolve reference "master".

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:12 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
mojavelinuxcommented, Apr 16, 2022

Yes, Antora supports git worktrees. See https://docs.antora.org/antora/latest/playbook/content-worktrees/ Please direct follow-up questions to the Antora project chat at https://chat.antora.org as we don’t want to bog down this issue talking about Antora.

1reaction
wmhiltoncommented, May 19, 2019

Ahhhh… hmm. Two more implementation notes for myself or whoever implements this feature.

  1. default argument values can’t be awaited. Since this will involve filesystem read, we’ll have to move initializing it into the body of the function.
  2. canonical git follows this “link” even if GIT_DIR is explicitly set. So really we should leave it there and it should look more like this:
import { join } from '../utils/join.js'
import { resolveGitDir } from '../utils/resolveGitDir.js'

function commit ({
  dir,
  gitdir = join(dir, '.git'),
  fs: _fs = cores.get(core).get('fs'),
  ...
}) {
  const fs = new FileSystem(_fs)
  gitdir = await resolveGitDir({ gitdir, fs })
  // do things with `dir` and `gitdir`
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

git-worktree Documentation - Git
A git repository can support multiple working trees, allowing you to check out more than one branch at a time. With git worktree...
Read more >
Why does git say "Pull is not possible because you have ...
It so happens, that your merge conflicts from (probably) the last commit were not not resolved, so your files are not merged all...
Read more >
477475 – git 2.5 worktree support - Bugs - Eclipse
I've dropped new private build with worktree support based at ... in case of official JGit that does not support worktrees (.git files)....
Read more >
Support additional worktrees · Issue #719 · gitpython ... - GitHub
I am curious how you got this working. The example where you used Repo.git.worktree("add", folder, branch) and then initialized with git.Repo() ...
Read more >
Support git worktree feature : IDEA-143404 - YouTrack
This new working tree is called a "linked working tree" as opposed to the "main working tree" prepared by "git init" or "git...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found