Skip to content

Commit

Permalink
Revert "Use current branch as a proxy for a valid git repository"
Browse files Browse the repository at this point in the history
This reverts commit 8e490d0.
  • Loading branch information
DanielThomas committed May 9, 2024
1 parent f3d692e commit cadf98d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 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)

String currentBranch = gitCommandUtil.currentBranch()
if (!currentBranch) {
boolean isGitRepo = gitCommandUtil.isGitRepo()
if(!isGitRepo) {
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 = currentBranch
it.branchName = gitCommandUtil.currentBranch()
it.patterns = nebulaReleaseExtension
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,23 @@ 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,6 +14,7 @@ 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 @@ -47,6 +48,9 @@ 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 @@ -105,6 +109,14 @@ 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 cadf98d

Please sign in to comment.