Skip to content

Commit

Permalink
Fix #540
Browse files Browse the repository at this point in the history
- Take care of system and user config
  • Loading branch information
arulrajnet committed Apr 2, 2022
1 parent 75e925f commit 6dfbc93
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
Expand Up @@ -172,7 +172,7 @@ static class RuntimeInit {
//////////////////////////
// REPO-SPECIFIC VALUES //
//////////////////////////
RepositorySpecificResolver repositoryResolver = GitWorkarounds.fileRepositoryResolverForProject(projectDir);
RepositorySpecificResolver repositoryResolver = GitWorkarounds.fileRepositoryResolverForProject(projectDir, userConfig);
if (repositoryResolver.getGitDir() != null) {
workTree = repositoryResolver.getWorkTree();
repoConfig = repositoryResolver.getRepositoryConfig();
Expand Down
Expand Up @@ -50,7 +50,7 @@ private GitWorkarounds() {}
* @return the path to the .git directory.
*/
static @Nullable File getDotGitDir(File projectDir) {
return fileRepositoryResolverForProject(projectDir).getGitDir();
return fileRepositoryResolverForProject(projectDir, null).getGitDir();
}

/**
Expand All @@ -61,8 +61,8 @@ private GitWorkarounds() {}
* @param projectDir the project directory.
* @return the builder.
*/
static RepositorySpecificResolver fileRepositoryResolverForProject(File projectDir) {
RepositorySpecificResolver repositoryResolver = new RepositorySpecificResolver();
static RepositorySpecificResolver fileRepositoryResolverForProject(File projectDir, Config baseConfig) {
RepositorySpecificResolver repositoryResolver = new RepositorySpecificResolver(baseConfig);
repositoryResolver.findGitDir(projectDir);
repositoryResolver.readEnvironment();
if (repositoryResolver.getGitDir() != null || repositoryResolver.getWorkTree() != null) {
Expand Down Expand Up @@ -94,6 +94,16 @@ static class RepositorySpecificResolver extends FileRepositoryBuilder {

private File commonDirectory;

private Config baseConfig;

public RepositorySpecificResolver() {
this(null);
}

public RepositorySpecificResolver(Config baseConfig) {
this.baseConfig = baseConfig;
}

/** @return the repository specific configuration. */
Config getRepositoryConfig() {
return Errors.rethrow().get(this::getConfig);
Expand All @@ -108,7 +118,12 @@ Config getRepositoryConfig() {
protected Config loadConfig() throws IOException {
if (getGitDir() != null) {
File path = resolveWithCommonDir(Constants.CONFIG);
FileBasedConfig cfg = new FileBasedConfig(path, safeFS());
FileBasedConfig cfg = null;
if (this.baseConfig == null) {
cfg = new FileBasedConfig(path, safeFS());
} else {
cfg = new FileBasedConfig(baseConfig, path, safeFS());
}
try {
cfg.load();

Expand Down

0 comments on commit 6dfbc93

Please sign in to comment.