From 8e99f0ddb5967f293360e873ccbecf331278ee1e Mon Sep 17 00:00:00 2001 From: Stefan Lange Date: Fri, 12 Dec 2014 00:54:16 +0100 Subject: [PATCH] Fix for https://github.com/ktoso/maven-git-commit-id-plugin/issues/146 : Now using SHA of commit in native git in case Repro is in detached HEAD-State and not in a CI-Environment, thats the same behavoir as in JGit-Implementation --- .../pl/project13/maven/git/NativeGitProvider.java | 12 +++++++++--- .../maven/git/GitCommitIdMojoIntegrationTest.java | 5 ----- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/main/java/pl/project13/maven/git/NativeGitProvider.java b/src/main/java/pl/project13/maven/git/NativeGitProvider.java index d78ef07b..87413e8b 100644 --- a/src/main/java/pl/project13/maven/git/NativeGitProvider.java +++ b/src/main/java/pl/project13/maven/git/NativeGitProvider.java @@ -73,9 +73,15 @@ protected String getBranchName() throws IOException { } private String getBranch(File canonical) { - String branch = tryToRunGitCommand(canonical, "symbolic-ref HEAD"); - if (branch != null) { - branch = branch.replace("refs/heads/", ""); + String branch = null; + try{ + branch = tryToRunGitCommand(canonical, "symbolic-ref HEAD"); + if (branch != null) { + branch = branch.replace("refs/heads/", ""); + } + }catch(RuntimeException e){ + // it seems that git repro is in 'DETACHED HEAD'-State, using Commid-Id as Branch + branch = getCommitId(); } return branch; } diff --git a/src/test/java/pl/project13/maven/git/GitCommitIdMojoIntegrationTest.java b/src/test/java/pl/project13/maven/git/GitCommitIdMojoIntegrationTest.java index 68b05585..3c2dbfd9 100644 --- a/src/test/java/pl/project13/maven/git/GitCommitIdMojoIntegrationTest.java +++ b/src/test/java/pl/project13/maven/git/GitCommitIdMojoIntegrationTest.java @@ -621,11 +621,6 @@ public void shouldExtractTagsOnGivenCommit(boolean useNativeGit) throws Exceptio @Test @Parameters(method = "useNativeGit") public void runGitDescribeWithMatchOption(boolean useNativeGit) throws Exception { - if (System.getenv().get("TRAVIS").equals("true") && System.getenv().get("CI").equals("true")) { - // FIXME: this test has trouble on travis, I think it's because of not pulling everything? - return; - } - // given mavenSandbox.withParentProject("my-pom-project", "pom") .withChildProject("my-jar-module", "jar")