aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit/src/org/eclipse/jgit
diff options
context:
space:
mode:
authorDavid Pursehouse <david.pursehouse@gmail.com>2017-02-07 07:31:03 -0500
committerGerrit Code Review @ Eclipse.org <gerrit@eclipse.org>2017-02-07 07:31:06 -0500
commit5336a0738669477830e258ed582df4afc705d513 (patch)
treecc5fb422d49ca161d3819e148ae7a7df480d3e7c /org.eclipse.jgit/src/org/eclipse/jgit
parent08480c948c47b905ace6ecec43ae0c92a218d1d6 (diff)
parentf8d232213cb502214dc7d490b1bc612f88f0635f (diff)
downloadjgit-5336a0738669477830e258ed582df4afc705d513.tar.gz
jgit-5336a0738669477830e258ed582df4afc705d513.zip
Merge "Branch normalizer should not normalize already valid branch names"
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse/jgit')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java16
1 files changed, 11 insertions, 5 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java
index 6be97ffda6..c59224e3ae 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java
@@ -1898,11 +1898,12 @@ public abstract class Repository implements AutoCloseable {
* Future implementations of this method could be more restrictive or more
* lenient about the validity of specific characters in the returned name.
* <p/>
- * The current implementation returns a trimmed string only containing word
- * characters ([a-zA-Z_0-9]) and hyphens ('-'). Colons are replaced by
- * hyphens. Repeating underscores and hyphens are replaced by a single
- * occurrence. Underscores and hyphens at the beginning of the string are
- * removed.
+ * The current implementation returns the trimmed input string if this is
+ * already a valid branch name. Otherwise it returns a trimmed string only
+ * containing word characters ([a-zA-Z_0-9]) and hyphens ('-'). Colons are
+ * replaced by hyphens. Repeating underscores and hyphens are replaced by a
+ * single occurrence. Underscores and hyphens at the beginning of the string
+ * are removed.
*
* @param name
* The name to normalize.
@@ -1916,6 +1917,11 @@ public abstract class Repository implements AutoCloseable {
return name;
}
String result = name.trim();
+ String fullName = result.startsWith(Constants.R_HEADS) ? result
+ : Constants.R_HEADS + result;
+ if (isValidRefName(fullName)) {
+ return result;
+ }
return result.replaceAll("\\s+([_:-])*?\\s+", "$1") //$NON-NLS-1$//$NON-NLS-2$
.replaceAll(":", "-") //$NON-NLS-1$//$NON-NLS-2$
.replaceAll("\\s+", "_") //$NON-NLS-1$//$NON-NLS-2$