Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Working with a repository that has a different working directory #1710

Open
LevonX opened this issue Oct 16, 2023 · 3 comments
Open

Working with a repository that has a different working directory #1710

LevonX opened this issue Oct 16, 2023 · 3 comments

Comments

@LevonX
Copy link

LevonX commented Oct 16, 2023

Hello!

I'm trying to use a repository that has been initialized like this:

mkdir git
mkdir work
git --git-dir=пit/test --work-tree=work/test init

But it doesn't work. For example, when requesting untracked_files I get the error:

    raise GitCommandError(remove_password_if_present(self.args), status, errstr)
git.exc.GitCommandError: Cmd('git') failed due to: exit code(128)
  cmdline: git status --porcelain --untracked-files
  stderr: 'fatal: not a git repository (or any of the parent directories): .git

My code:

repo = Repo(repo_path)
print(repo.untracked_files())
@Byron
Copy link
Member

Byron commented Oct 16, 2023

Thanks for reporting!

There most definitely isn't any test for this usecase, and certain assumptions aren't met anymore leading to this failure.

The trick here is that git stores the worktree location in its configuration, which allows it work as normal at least while the CWD is the repository itself.

[core]
	repositoryformatversion = 0
	filemode = true
	bare = false
	logallrefupdates = true
	worktree = /path/to/separate-work-dir
	ignorecase = true
	precomposeunicode = true

gitoxide also has a problem with that and I will fix it there - for GitPython we will have to hope for a contribution though.

@pushfoo
Copy link

pushfoo commented Oct 16, 2023

and certain assumptions aren't met anymore leading to this failure.

Can you go more into depth about this? I suspect this or other assumptions may have something to with the issue I reported earlier today.

@Byron
Copy link
Member

Byron commented Oct 16, 2023

Unfortunately I can't, by now it's all guess-work and intuition. I don't think the issue you might be referring to is related though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants