Skip to content

Commit

Permalink
Merge pull request #33 from pmarkiewka/develop
Browse files Browse the repository at this point in the history
Checkout -B functionality
  • Loading branch information
schnatterer authored May 4, 2020
2 parents 52a1c84 + 56bc65d commit 7666cac
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,8 @@ gitWithCreds 'https://your.repo' // Implicitly passed credentials

### Changes to local repository

* `git.checkout('branchname')`
* `git.checkoutOrCreate('branchname')` - Creates new Branch if it does not exist; otherwise, it is reset
* `git.add('.')`
* `git.commit('message', 'Author', '[email protected])`
* `git.commit('message')` - uses the name and email of the last committer as author and committer.
Expand Down
11 changes: 11 additions & 0 deletions src/com/cloudogu/ces/cesbuildlib/Git.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,17 @@ class Git implements Serializable {
script.sh "git checkout ${branchName}"
}

/**
* Switch branch of the local repository. Creates new Branch if it does not exist; otherwise, it is reset
* Note: In a multibranch pipeline Jenkins will only fetch the changed branch,
* so you have to call {@link #fetch()} before checkout.
*
* @param branchName name of branch to switch to
*/
void checkoutOrCreate(String branchName) {
script.sh "git checkout -B ${branchName}"
}

/**
* Merge branch into the current checked out branch.
*
Expand Down
9 changes: 9 additions & 0 deletions test/com/cloudogu/ces/cesbuildlib/GitTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,15 @@ class GitTest {
assert scriptMock.actualShStringArgs[0] == "git checkout master"
}

@Test
void switchBranch() {
ScriptMock scriptMock = new ScriptMock()
Git git = new Git(scriptMock)
git.checkoutOrCreate("master")

assert scriptMock.actualShStringArgs[0] == "git checkout -B master"
}

@Test
void merge() {
ScriptMock scriptMock = new ScriptMock()
Expand Down

0 comments on commit 7666cac

Please sign in to comment.