summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit
diff options
context:
space:
mode:
authorKevin Sawicki <kevin@github.com>2012-03-19 18:03:20 -0700
committerChris Aniszczyk <zx@twitter.com>2012-03-21 10:20:54 -0700
commitfd0c468b7a181062eee910c655ec843950a7b51c (patch)
tree95fba11e8b2f0eec6cb78e4cbb371ffe2368ca02 /org.eclipse.jgit
parent04ab2dac3728f8e43dc42a9e700819dd2e7a4a93 (diff)
downloadjgit-fd0c468b7a181062eee910c655ec843950a7b51c.tar.gz
jgit-fd0c468b7a181062eee910c655ec843950a7b51c.zip
Copy all branch configuration values when renaming
Previously only certain values were copied over which caused divergence in behavior between the JGit command and corresponding CGit command. Bug: 372051 Change-Id: I72a83215a679a713138da31f5ab838f14388d4bd Signed-off-by: Chris Aniszczyk <zx@twitter.com>
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/api/RenameBranchCommand.java68
1 files changed, 37 insertions, 31 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/RenameBranchCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/RenameBranchCommand.java
index 99dc785b8a..f5dfa2b111 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/api/RenameBranchCommand.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/RenameBranchCommand.java
@@ -45,6 +45,7 @@ package org.eclipse.jgit.api;
import java.io.IOException;
import java.text.MessageFormat;
+import java.util.Arrays;
import org.eclipse.jgit.api.errors.DetachedHeadException;
import org.eclipse.jgit.api.errors.InvalidRefNameException;
@@ -138,41 +139,46 @@ public class RenameBranchCommand extends GitCommand<Ref> {
setCallable(false);
- boolean ok = Result.RENAMED == renameResult;
+ if (Result.RENAMED != renameResult)
+ throw new JGitInternalException(MessageFormat.format(JGitText
+ .get().renameBranchUnexpectedResult, renameResult
+ .name()));
- if (ok) {
- if (fullNewName.startsWith(Constants.R_HEADS)) {
- // move the upstream configuration over to the new branch
- String shortOldName = fullOldName
- .substring(Constants.R_HEADS.length());
- final StoredConfig repoConfig = repo.getConfig();
- String oldRemote = repoConfig.getString(
+ if (fullNewName.startsWith(Constants.R_HEADS)) {
+ String shortOldName = fullOldName.substring(Constants.R_HEADS
+ .length());
+ final StoredConfig repoConfig = repo.getConfig();
+ // Copy all configuration values over to the new branch
+ for (String name : repoConfig.getNames(
+ ConfigConstants.CONFIG_BRANCH_SECTION, shortOldName)) {
+ String[] values = repoConfig.getStringList(
ConfigConstants.CONFIG_BRANCH_SECTION,
- shortOldName, ConfigConstants.CONFIG_KEY_REMOTE);
- if (oldRemote != null) {
- repoConfig.setString(
- ConfigConstants.CONFIG_BRANCH_SECTION, newName,
- ConfigConstants.CONFIG_KEY_REMOTE, oldRemote);
+ shortOldName, name);
+ if (values.length == 0)
+ continue;
+ // Keep any existing values already configured for the
+ // new branch name
+ String[] existing = repoConfig.getStringList(
+ ConfigConstants.CONFIG_BRANCH_SECTION, newName,
+ name);
+ if (existing.length > 0) {
+ String[] newValues = new String[values.length
+ + existing.length];
+ System.arraycopy(existing, 0, newValues, 0,
+ existing.length);
+ System.arraycopy(values, 0, newValues, existing.length,
+ values.length);
+ values = newValues;
}
- String oldMerge = repoConfig.getString(
- ConfigConstants.CONFIG_BRANCH_SECTION,
- shortOldName, ConfigConstants.CONFIG_KEY_MERGE);
- if (oldMerge != null) {
- repoConfig.setString(
- ConfigConstants.CONFIG_BRANCH_SECTION, newName,
- ConfigConstants.CONFIG_KEY_MERGE, oldMerge);
- }
- repoConfig
- .unsetSection(
- ConfigConstants.CONFIG_BRANCH_SECTION,
- shortOldName);
- repoConfig.save();
- }
- } else
- throw new JGitInternalException(MessageFormat.format(JGitText
- .get().renameBranchUnexpectedResult, renameResult
- .name()));
+ repoConfig.setStringList(
+ ConfigConstants.CONFIG_BRANCH_SECTION, newName,
+ name, Arrays.asList(values));
+ }
+ repoConfig.unsetSection(ConfigConstants.CONFIG_BRANCH_SECTION,
+ shortOldName);
+ repoConfig.save();
+ }
Ref resultRef = repo.getRef(newName);
if (resultRef == null)