Skip to content

Commit

Permalink
GetGitConfigValue should use --includes to respect include.* directiv…
Browse files Browse the repository at this point in the history
…es in config files when looking up values
  • Loading branch information
rpalcolea committed Jan 9, 2024
1 parent c5f89fe commit 5e778b6
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ abstract class GetGitConfigValue extends GitReadCommand {
String obtain() {
try {
if(parameters.getGitConfigScope().isPresent()) {
return executeGitCommand( "config", parameters.getGitConfigScope().get(), parameters.getGitConfigKey().get())
return executeGitCommand( "config", parameters.getGitConfigScope().get(), "--includes", parameters.getGitConfigKey().get())
} else {
return executeGitCommand( "config", parameters.getGitConfigKey().get())
}
Expand All @@ -323,20 +323,3 @@ abstract class GetGitConfigValue extends GitReadCommand {
}
}


/**
* Set a given Git config key with its value for a given scope
*/
abstract class SetGitConfigValue extends GitReadCommand {
private static final Logger logger = LoggerFactory.getLogger(SetGitConfigValue)
@Override
String obtain() {
try {
return executeGitCommand( "config", parameters.getGitConfigKey().get(), parameters.getGitConfigValue().get())
} catch (Exception e) {
logger.debug("Could not set git config {} {} {}", parameters.getGitConfigKey().get(), parameters.getGitConfigValue().get())
return null
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,6 @@ class GitReadOnlyCommandUtil implements Serializable {
}
}

String getUsernameFromLog() {
try {
return currentBranchProvider.get().toString().replaceAll("\n", "").trim()
} catch (Exception e) {
return null
}
}

Boolean hasCommit() {
try {
String describe = anyCommitProvider.get().toString()
Expand Down Expand Up @@ -154,8 +146,6 @@ class GitReadOnlyCommandUtil implements Serializable {
}
}



String describeHeadWithTags(boolean excludePreReleases) {
try {
def describeTagInHeadProvider = excludePreReleases ? providers.of(DescribeHeadWithTagWithExclude.class) {
Expand Down Expand Up @@ -278,24 +268,4 @@ class GitReadOnlyCommandUtil implements Serializable {
return null
}
}

/**
* Returns a git config value for a given scope
* @param scope
* @param configKey
* @return
*/
void setGitConfig(String configKey, String configValue) {
try {
def getConfigValueProvider = providers.of(SetGitConfigValue.class) {
it.parameters.rootDir.set(rootDir)
it.parameters.gitConfigKey.set(configKey)
it.parameters.gitConfigValue.set(configValue)
}
getConfigValueProvider.get().toString()?.
replaceAll("\n", "")?.toString()
} catch(Exception e) {
logger.debug("Could not set git config {} {}", configKey, configValue)
}
}
}

0 comments on commit 5e778b6

Please sign in to comment.