Skip to content

Commit

Permalink
Use current branch as a proxy for a valid git repository
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielThomas committed May 9, 2024
1 parent ecc064d commit 8e490d0
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 32 deletions.
6 changes: 3 additions & 3 deletions src/main/groovy/nebula/plugin/release/ReleasePlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ class ReleasePlugin implements Plugin<Project> {
gitCommandUtil.configure(gitRoot, shouldVerifyUserGitConfig)
gitWriteCommandsUtil.configure(gitRoot)

boolean isGitRepo = gitCommandUtil.isGitRepo()
if(!isGitRepo) {
boolean currentBranch = gitCommandUtil.currentBranch()
if (!currentBranch) {
this.project.version = '0.1.0-dev.0.uncommitted'
logger.warn("Git repository not found at $gitRoot -- nebula-release tasks will not be available. Use the git.root Gradle property to specify a different directory.")
return
Expand Down Expand Up @@ -126,7 +126,7 @@ class ReleasePlugin implements Plugin<Project> {

TaskProvider<ReleaseCheck> releaseCheck = project.tasks.register(RELEASE_CHECK_TASK_NAME, ReleaseCheck) {
it.group = GROUP
it.branchName = gitCommandUtil.currentBranch()
it.branchName = currentBranch
it.patterns = nebulaReleaseExtension
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,23 +205,6 @@ abstract class IsCurrentBranchBehindRemote extends GitReadCommand {
}
}

/**
* Used to check if the current directory is a git repo
* ex. git rev-parse --is-inside-work-tree -> true OR
* git rev-parse --is-inside-work-tree -> fatal: not a git repository (or any of the parent directories): .git when there isn't a repo
*/
abstract class IsGitRepo extends GitReadCommand {

@Override
String obtain() {
try {
return !executeGitCommand( "rev-parse").contains("fatal: not a git repository")
} catch (Exception e) {
return false
}
}
}

/**
* Used to verify if the current branch is tracking a remote branch
* ex. git rev-parse --abbrev-ref --symbolic-full-name @{u} -> origin/main
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ class GitReadOnlyCommandUtil implements Serializable {
private Provider usernameFromLogProvider
private Provider emailFromLogProvider
private Provider currentBranchProvider
private Provider isGitRepoProvider
private Provider anyCommitProvider
private Provider revParseHeadProvider
private Provider headTagsProvider
Expand Down Expand Up @@ -48,9 +47,6 @@ class GitReadOnlyCommandUtil implements Serializable {
currentBranchProvider = providers.of(CurrentBranch.class) {
it.parameters.rootDir.set(rootDir)
}
isGitRepoProvider = providers.of(IsGitRepo.class) {
it.parameters.rootDir.set(rootDir)
}
anyCommitProvider = providers.of(AnyCommit.class) {
it.parameters.rootDir.set(rootDir)
}
Expand Down Expand Up @@ -109,14 +105,6 @@ class GitReadOnlyCommandUtil implements Serializable {
}
}

Boolean isGitRepo() {
try {
return Boolean.valueOf(isGitRepoProvider.get().toString())
} catch (Exception e) {
return false
}
}

Boolean hasCommit() {
try {
String describe = anyCommitProvider.get().toString()
Expand Down

0 comments on commit 8e490d0

Please sign in to comment.