From 8e490d0e1a08802341ffaa7a7556aee2ce42f5e3 Mon Sep 17 00:00:00 2001 From: Danny Thomas Date: Thu, 9 May 2024 02:26:52 +0000 Subject: [PATCH] Use current branch as a proxy for a valid git repository --- .../nebula/plugin/release/ReleasePlugin.groovy | 6 +++--- .../release/git/command/GitReadCommand.groovy | 17 ----------------- .../git/command/GitReadOnlyCommandUtil.groovy | 12 ------------ 3 files changed, 3 insertions(+), 32 deletions(-) diff --git a/src/main/groovy/nebula/plugin/release/ReleasePlugin.groovy b/src/main/groovy/nebula/plugin/release/ReleasePlugin.groovy index 750af77..1b65ce3 100644 --- a/src/main/groovy/nebula/plugin/release/ReleasePlugin.groovy +++ b/src/main/groovy/nebula/plugin/release/ReleasePlugin.groovy @@ -74,8 +74,8 @@ class ReleasePlugin implements Plugin { 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 @@ -126,7 +126,7 @@ class ReleasePlugin implements Plugin { TaskProvider releaseCheck = project.tasks.register(RELEASE_CHECK_TASK_NAME, ReleaseCheck) { it.group = GROUP - it.branchName = gitCommandUtil.currentBranch() + it.branchName = currentBranch it.patterns = nebulaReleaseExtension } diff --git a/src/main/groovy/nebula/plugin/release/git/command/GitReadCommand.groovy b/src/main/groovy/nebula/plugin/release/git/command/GitReadCommand.groovy index d4733fe..6b3fd56 100644 --- a/src/main/groovy/nebula/plugin/release/git/command/GitReadCommand.groovy +++ b/src/main/groovy/nebula/plugin/release/git/command/GitReadCommand.groovy @@ -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 diff --git a/src/main/groovy/nebula/plugin/release/git/command/GitReadOnlyCommandUtil.groovy b/src/main/groovy/nebula/plugin/release/git/command/GitReadOnlyCommandUtil.groovy index 85a9d78..d2a5bf6 100644 --- a/src/main/groovy/nebula/plugin/release/git/command/GitReadOnlyCommandUtil.groovy +++ b/src/main/groovy/nebula/plugin/release/git/command/GitReadOnlyCommandUtil.groovy @@ -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 @@ -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) } @@ -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()