Add getBranchesForGitRepo function to Git.groovy class
Related: PROD-27028 (PROD:27028)
Change-Id: I092e5389fdce4bdbbaaa240b0e22464e524dbcd1
(cherry picked from commit 765f7baf459722b1960d37f914ea40757e3e026c)
diff --git a/src/com/mirantis/mk/Git.groovy b/src/com/mirantis/mk/Git.groovy
index d20c159..919acb9 100644
--- a/src/com/mirantis/mk/Git.groovy
+++ b/src/com/mirantis/mk/Git.groovy
@@ -206,3 +206,24 @@
}
sh "git remote rm target"
}
+
+
+/**
+ * Return all branches for the defined git repository that match the matcher.
+ *
+ * @param repoUrl URL of git repository
+ * @param branchMatcher matcher to filter out the branches (If '' or '*', returns all branches without filtering)
+ * @return branchesList list of branches
+ */
+
+def getBranchesForGitRepo(repoUrl, branchMatcher = ''){
+
+ if (branchMatcher.equals("*")) {
+ branchMatcher = ''
+ }
+ branchesList = sh (
+ script: "git ls-remote --heads ${repoUrl} | cut -f2 | grep -e '${branchMatcher}' | sed 's/refs\\/heads\\///g'",
+ returnStdout: true
+ ).trim()
+ return branchesList.tokenize('\n')
+}
\ No newline at end of file