Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EGit / JGit » Overriding Git config file without a file based config(As a solution for disabling symlinks and hooks)
Overriding Git config file without a file based config [message #1840236] Fri, 09 April 2021 11:25 Go to next message
Elias Kassell is currently offline Elias KassellFriend
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 #1840248 is a reply to message #1840236] Fri, 09 April 2021 15:48 Go to previous messageGo to next message
Thomas Wolf is currently offline Thomas WolfFriend
Messages: 576
Registered: August 2016
Senior Member
Elias Kassell wrote on Fri, 09 April 2021 11:25
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.

That's not what the linked code does. It just reads the "init.defaultbranch" setting from the git user config. It does not copy the user config to .git/config. (Which is how I understand "...is sourced from...".)

The initial .git/config is written in FileRepository.create().

Probably the easiest way to achieve what you want is to do the clone step-by-step: git init, then adapt the git config in .git/config as you need, add a remote, git fetch, make sure HEAD and the initial branch point to the correct upstream branch just fetched, then checkout.
Re: Overriding Git config file without a file based config [message #1840313 is a reply to message #1840248] Mon, 12 April 2021 10:36 Go to previous messageGo to next message
Elias Kassell is currently offline Elias KassellFriend
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.
Re: Overriding Git config file without a file based config [message #1840324 is a reply to message #1840313] Mon, 12 April 2021 13:32 Go to previous message
Thomas Wolf is currently offline Thomas WolfFriend
Messages: 576
Registered: August 2016
Senior Member
Normally git configs are checked bottom up. So entries in .git/config can override entries in the user config, which can override entries from the system config.

If you want some non-standard behavior in which the user and system config are always ignored, you would indeed have to use your own SystemReader that returns empty in-memory configs. Take a look at MockSystemReader; a similar approach might work for your use case, too.
Previous Topic:Warning message in JGit for pull and push
Next Topic:Unable to clone repo in ssh or https in 5.12
Goto Forum:
  


Current Time: Tue Apr 23 18:02:02 GMT 2024

Powered by FUDForum. Page generated in 0.03305 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top