aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMathias Kinzler2010-10-11 09:33:32 (EDT)
committerShawn O. Pearce2010-10-12 15:22:40 (EDT)
commit5c135a5856654c6403c252bf3912f91a8c80e017 (patch)
tree4c3488ab76bd36257f1701da9bd38d0f6a80a89b
parent4ac3d9814c72c2cb14fc2bea4ea467f08ed44c48 (diff)
downloadjgit-5c135a5856654c6403c252bf3912f91a8c80e017.zip
jgit-5c135a5856654c6403c252bf3912f91a8c80e017.tar.gz
jgit-5c135a5856654c6403c252bf3912f91a8c80e017.tar.bz2
DeleteBranchCommand does not clean up upstream configurationrefs/changes/27/1727/2
It wrongly uses the full name of the branch to remove the configuration entries but must use the shortened one. Change-Id: Ie386a128a6c6beccc20bafd15c2e36254c5f560d Signed-off-by: Mathias Kinzler <mathias.kinzler@sap.com>
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/BranchCommandTest.java13
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/api/DeleteBranchCommand.java20
2 files changed, 25 insertions, 8 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/BranchCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/BranchCommandTest.java
index 8b5688c..83f161e 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/BranchCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/BranchCommandTest.java
@@ -287,6 +287,16 @@ public class BranchCommandTest extends RepositoryTestCase {
// the pull configuration should be gone after deletion
assertNull(localGit.getRepository().getConfig().getString("branch",
"newFromRemote", "remote"));
+
+ createBranch(localGit, "newFromRemote", false, remote.getName(), null);
+ assertEquals("origin", localGit.getRepository().getConfig().getString(
+ "branch", "newFromRemote", "remote"));
+ localGit.branchDelete().setBranchNames("refs/heads/newFromRemote")
+ .call();
+ // the pull configuration should be gone after deletion
+ assertNull(localGit.getRepository().getConfig().getString("branch",
+ "newFromRemote", "remote"));
+
// use --no-track
createBranch(localGit, "newFromRemote", false, remote.getName(),
SetupUpstreamMode.NOTRACK);
@@ -307,7 +317,8 @@ public class BranchCommandTest extends RepositoryTestCase {
SetupUpstreamMode.TRACK);
assertEquals(".", localGit.getRepository().getConfig().getString(
"branch", "newFromMaster", "remote"));
- localGit.branchDelete().setBranchNames("newFromMaster").call();
+ localGit.branchDelete().setBranchNames("refs/heads/newFromMaster")
+ .call();
// the pull configuration should be gone after deletion
assertNull(localGit.getRepository().getConfig().getString("branch",
"newFromRemote", "remote"));
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/DeleteBranchCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/DeleteBranchCommand.java
index c0d95f3..fa00581 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/api/DeleteBranchCommand.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/DeleteBranchCommand.java
@@ -127,13 +127,14 @@ public class DeleteBranchCommand extends GitCommand<List<String>> {
Ref currentRef = repo.getRef(branchName);
if (currentRef == null)
continue;
- if (currentRef.getName().equals(currentBranch))
+ String fullName = currentRef.getName();
+ if (fullName.equals(currentBranch))
throw new CannotDeleteCurrentBranchException(
MessageFormat
.format(
JGitText.get().cannotDeleteCheckedOutBranch,
branchName));
- RefUpdate update = repo.updateRef(currentRef.getName());
+ RefUpdate update = repo.updateRef(fullName);
update.setRefLogMessage("branch deleted", false);
update.setForceUpdate(true);
Result deleteResult = update.delete();
@@ -150,11 +151,16 @@ public class DeleteBranchCommand extends GitCommand<List<String>> {
}
if (ok) {
- result.add(currentRef.getName());
- // remove upstream configuration if any
- repo.getConfig().unsetSection(
- ConfigConstants.CONFIG_BRANCH_SECTION, branchName);
- repo.getConfig().save();
+ result.add(fullName);
+ if (fullName.startsWith(Constants.R_HEADS)) {
+ String shortenedName = fullName
+ .substring(Constants.R_HEADS.length());
+ // remove upstream configuration if any
+ repo.getConfig().unsetSection(
+ ConfigConstants.CONFIG_BRANCH_SECTION,
+ shortenedName);
+ repo.getConfig().save();
+ }
} else
throw new JGitInternalException(MessageFormat.format(
JGitText.get().deleteBranchUnexpectedResult,