Overriding Git config file without a file based config [message #1840236] |
Fri, 09 April 2021 11:25 |
Elias Kassell Messages: 2 Registered: April 2021 |
Junior Member |
|
|
Hello, I need to ensure that symlinks and hooks are disabled during all Git operations for a repo.
The most sensible way to achieve this with JGit seems to be making sure that during clone the initial `.git/config` has the base of:
```
[core]
filemode = true
symlinks = false
hooksPath = /empty
```
In an ideal situation I'd be able to pass in a constructed `org.eclipse.jgit.lib.Config` to the `org.eclipse.jgit.api.CloneCommand` to use as the base, but that isn't a feature.
The initial Git config file is sourced from the default User Git config file from specified by the current SystemReader instance during the repo init to .git/config: https://git.eclipse.org/c/jgit/jgit.git/tree/org.eclipse.jgit/src/org/eclipse/jgit/api/InitCommand.java#n96.
I do however want to be able to do this requiring a particular file in the filesystem, as during unit testing mutants won't be found from changing lines of that Git config file, and avoiding files will make the solution deployment agnostic.
I tried overriding the SystemReader, making `openUserConfig` return a `FileBasedConfig` extending a constructed `Config` of my own design, with save and load overridden as no-ops to prevent it interacting with the filesystem, but ran into various null pointer issues.
Has anyone done this, have example code or any suggestions on how to progress, other than implementing setConfig as part of the clone command?
|
|
|
|
Re: Overriding Git config file without a file based config [message #1840313 is a reply to message #1840248] |
Mon, 12 April 2021 10:36 |
Elias Kassell Messages: 2 Registered: April 2021 |
Junior Member |
|
|
Ah, thanks for correcting my misunderstanding, and for your response.
I've realised my original suggested solution may have obfuscated the title of my post. I want to be able to not have Git config files read from disk at all, from .git/config or from the system/user/jgit config. If .git/config is required, then not read files from the system/user/jgit config. And I want to be able to do this for not just cloning, but all subsequent JGit operations.
My current workaround is exactly as you suggested, manually creating the .git/config file, inserting it while recreating clone from its components. This semi-solves half the problem though.
During other Git operations, (correct me if I'm wrong here) the other Git configs in the hierarchy will be checked first, for example looking for a global user.name; I currently have not found a solution for avoiding this.
|
|
|
|
Powered by
FUDForum. Page generated in 0.03305 seconds