feat(config): added GitDir to get proper location to put local configs
-
Please check this box if this contribution uses AI-generated content (including content generated by GitLab Duo features) as outlined in the GitLab DCO & CLA. As a benefit of being a GitLab Community Contributor, you receive complimentary access to GitLab Duo.
Description
I usually use worktrees and submodules, that is why I wanted to let glab work with those. This implements it in a bare minimum way to expand on it.
I am not very proud of commands/project/create/project_create.go
suggestions are welcome.
some information about the code:
git rev-parse --git-dir exists since git v1.2.2
--show-prefix exists since v1.0.0 (an earlier), but requires manually
resolving git file/directory.
I have no idea how to properly write a test for GitDir in internal/config/local_config.go.
I would not write a test for filepath.Rel which means I would test
preferRelative. The only thing which I came up with was manually finding and parsing
.git files/directories, but that would be a test of git itself and not of the functionality.
Using Cmd twice, both with the same parameters seems pretty dull. Maybe checking
the equivalence of GitDir(true) and GitDir(false) by checking some kind of file id?
Note that I am new to committing go related code and am not familiar with the coding conventions here. I tried my best to follow them.
- added GitDir to get proper location to put local configs
GitDir can ignore preferRelative and is not meant to deliver consistent
locations. It depends on git v1.2.2 and its behaviour. GitDir(true) and
GitDir(false) should point to the same location. Relative paths should
be prefered when working with worktrees and submodules.
Related Issues
Resolves #7872 (closed)
How has this been tested?
I ran LC_ALL=C make test for confirmation. I do not yet have the gitlab pipelines enabled for my account.
It ran inside a clean docker ubuntu:24.04 with minimal installations.
Testing might get annoying as the git directory changes depending on the repository setup.
The implementation of GitDir also takes a bool to prefer relative or absolute paths, but it still can
fallback to use the other. However GitDir(false) should point to the same directory as GitDir(true)
Types of changes
-
Bug fix (non-breaking change which fixes an issue) -
New feature (non-breaking change which adds functionality) -
Breaking change (fix or feature that would cause existing functionality to change) -
Documentation -
Chore (Related to CI or Packaging to platforms) -
Test gap