[Git] Add getBranchesContainsTag method
This method allow to get branch list which contains selected tag
Related-Prod: PRODX-3456
Change-Id: I9acc737b86a060327bc8dc43bfed704ddb282532
diff --git a/src/com/mirantis/mk/Git.groovy b/src/com/mirantis/mk/Git.groovy
index a5203f5..667e43c 100644
--- a/src/com/mirantis/mk/Git.groovy
+++ b/src/com/mirantis/mk/Git.groovy
@@ -619,3 +619,25 @@
}
return jsonChange
}
+
+/**
+ * Return array with branches that contains specific tag
+ *
+ * @param path Path to the git repository
+ * @param tag search tag
+ */
+def getBranchesContainsTag(String path, String tag) {
+ List result = []
+ dir(path) {
+ def gitResult = sh (
+ script: "git branch --all --contains tags/${tag}",
+ returnStdout: true
+ )
+ for (line in gitResult.split('\n')) {
+ if (! line.contains("HEAD detached")) {
+ result.add(line.trim().replaceAll('remotes/origin/', ''))
+ }
+ }
+ }
+ return result
+}