mirror of
https://github.com/SAP/jenkins-library.git
synced 2024-12-14 11:03:09 +02:00
Merge pull request #150 from marcusholl/pr/insideWorkingTree
git utils: is inside working tree
This commit is contained in:
commit
3ae2d0ae47
@ -1,7 +1,11 @@
|
||||
package com.sap.piper
|
||||
|
||||
boolean insideWorkTree() {
|
||||
return sh(returnStatus: true, script: 'git rev-parse --is-inside-work-tree 1>/dev/null 2>&1') == 0
|
||||
}
|
||||
|
||||
String getGitCommitIdOrNull() {
|
||||
if (sh(returnStatus: true, script: 'git rev-parse --is-inside-work-tree 1>/dev/null 2>&1') == 0) {
|
||||
if ( insideWorkTree() ) {
|
||||
return getGitCommitId()
|
||||
} else {
|
||||
return null
|
||||
|
@ -10,6 +10,8 @@ import util.JenkinsShellCallRule
|
||||
import util.Rules
|
||||
|
||||
import static org.junit.Assert.assertEquals
|
||||
import static org.junit.Assert.assertFalse
|
||||
import static org.junit.Assert.assertTrue
|
||||
import static org.junit.Assert.assertNull
|
||||
|
||||
class GitUtilsTest extends BasePiperTest {
|
||||
@ -25,6 +27,19 @@ class GitUtilsTest extends BasePiperTest {
|
||||
jscr.setReturnValue('git rev-parse HEAD', 'testCommitId')
|
||||
}
|
||||
|
||||
@Test
|
||||
void TestIsInsideWorkTree() {
|
||||
jscr.setReturnValue('git rev-parse --is-inside-work-tree 1>/dev/null 2>&1', 0)
|
||||
assertTrue(gitUtils.insideWorkTree())
|
||||
}
|
||||
|
||||
@Test
|
||||
void TestIsNotInsideWorkTree() {
|
||||
jscr.setReturnValue('git rev-parse --is-inside-work-tree 1>/dev/null 2>&1', 1)
|
||||
assertFalse(gitUtils.insideWorkTree())
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void testGetGitCommitId() {
|
||||
jscr.setReturnValue('git rev-parse --is-inside-work-tree 1>/dev/null 2>&1', 0)
|
||||
|
Loading…
Reference in New Issue
Block a user