Skip to content

Calculate the default for index relative to git_dir instead of work_tree #499

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

Merged
merged 1 commit into from
Dec 22, 2020
Merged

Calculate the default for index relative to git_dir instead of work_tree #499

merged 1 commit into from
Dec 22, 2020

Conversation

jcouball
Copy link
Member

Your checklist for this pull request

🚨Please review the guidelines for contributing to this repository.

  • Ensure all commits include DCO sign-off.
  • Ensure that your contributions pass unit testing.
  • Ensure that your contributions contain documentation if applicable.

Description

index when not given, defaults to "#{work_tree}/.git/index". This only works as long as git_dir is "#{work_tree}/.git". In the general case, the index default should be #{git_dir}/index.

This PR adds two tests:

  • TestGitDir#test_index_calculated_from_git_dir which tests that index is calculated correctly when git_dir is not "#{work_tree}/.git/index"
  • TestGitDir#test_git_dir_outside_work_tree which tests that when git_dir is in a non-standard location, Git.open and option functions work.

Fix the case in Base#open where the --git-dir is a file as is the case with Submodules and (non-main) Worktrees. This case was handled for Base.init but not Base.open.

tests/test_helper.rb was changed so that MiniTest classes that do not call set_file_paths do not output a warning because @tmp_path is referenced without being defined.

@jcouball
Copy link
Member Author

@SolaWing reported the following in #479:

git diff in worktree is broken. report index file open failed: Not a directory. and debug, the GIT_INDEX_FILE environment is set to wrong path

@SolaWing I am having a hard time reproducing your problem. Can you provide a reproduction recipe? If you can do that, I'll make sure that there is a test for what you are reporting and that this change addresses the issue.

@SolaWing
Copy link

@SolaWing reported the following in #479:

git diff in worktree is broken. report index file open failed: Not a directory. and debug, the GIT_INDEX_FILE environment is set to wrong path

@SolaWing I am having a hard time reproducing your problem. Can you provide a reproduction recipe? If you can do that, I'll make sure that there is a test for what you are reporting and that this change addresses the issue.

Reproduce script:

mkdir git_root
cd git_root
git init
git commit --allow-empty -m 'init'
git worktree add child
cd child/
ruby -rgit -e 'Git.open(".").diff.to_a'
# clean
cd ../..
rm -rf git_root

@jcouball
Copy link
Member Author

@SolaWing I have added the test TestGitDir::test_git_diff_to_a which fails in the way you describe without this change and succeeds with this change.

Signed-off-by: James Couball <couballj@verizonmedia.com>
@jcouball jcouball merged commit c81cc03 into ruby-git:master Dec 22, 2020
@jcouball jcouball deleted the relative_index branch December 22, 2020 17:31
@aquaflamingo
Copy link

nice!

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

Successfully merging this pull request may close these issues.

3 participants