Skip to content

Commit

Permalink
GitReadOnlyCommandUtil: check for commits should not rely on tags sin…
Browse files Browse the repository at this point in the history
…ce it doesn't support detached state
  • Loading branch information
rpalcolea committed Dec 6, 2023
1 parent 4690920 commit 95d2f18
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,11 @@ abstract class CommitFromTag extends GitReadCommand {
/**
* Uses to determine if a given repo has any commit
*/
abstract class DescribeTags extends GitReadCommand {
abstract class AnyCommit extends GitReadCommand {
@Override
String obtain() {
try {
return executeGitCommand( "describe", "--tags", "--always")
return executeGitCommand( "rev-list", "-n", "1", "--all")
.replaceAll("\n", "").trim()
} catch (Exception e) {
return null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class GitReadOnlyCommandUtil implements Serializable {
private Provider emailFromLogProvider
private Provider currentBranchProvider
private Provider isGitRepoProvider
private Provider describeTagsProvider
private Provider anyCommitProvider
private Provider revParseHeadProvider
private Provider headTagsProvider
private Provider refTagsProvider
Expand Down Expand Up @@ -48,7 +48,7 @@ class GitReadOnlyCommandUtil implements Serializable {
isGitRepoProvider = providers.of(IsGitRepo.class) {
it.parameters.rootDir.set(rootDir)
}
describeTagsProvider = providers.of(DescribeTags.class) {
anyCommitProvider = providers.of(AnyCommit.class) {
it.parameters.rootDir.set(rootDir)
}
revParseHeadProvider = providers.of(RevParseHead.class) {
Expand Down Expand Up @@ -108,8 +108,8 @@ class GitReadOnlyCommandUtil implements Serializable {

Boolean hasCommit() {
try {
String describe = describeTagsProvider.get().toString()
return describe != null && !describe.contains("fatal:")
String describe = anyCommitProvider.get().toString()
return describe != null && !describe.empty && !describe.contains("fatal:")
} catch (Exception e) {
return false
}
Expand Down

0 comments on commit 95d2f18

Please sign in to comment.