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>tags/v0.10.1
// the pull configuration should be gone after deletion | // the pull configuration should be gone after deletion | ||||
assertNull(localGit.getRepository().getConfig().getString("branch", | assertNull(localGit.getRepository().getConfig().getString("branch", | ||||
"newFromRemote", "remote")); | "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 | // use --no-track | ||||
createBranch(localGit, "newFromRemote", false, remote.getName(), | createBranch(localGit, "newFromRemote", false, remote.getName(), | ||||
SetupUpstreamMode.NOTRACK); | SetupUpstreamMode.NOTRACK); | ||||
SetupUpstreamMode.TRACK); | SetupUpstreamMode.TRACK); | ||||
assertEquals(".", localGit.getRepository().getConfig().getString( | assertEquals(".", localGit.getRepository().getConfig().getString( | ||||
"branch", "newFromMaster", "remote")); | "branch", "newFromMaster", "remote")); | ||||
localGit.branchDelete().setBranchNames("newFromMaster").call(); | |||||
localGit.branchDelete().setBranchNames("refs/heads/newFromMaster") | |||||
.call(); | |||||
// the pull configuration should be gone after deletion | // the pull configuration should be gone after deletion | ||||
assertNull(localGit.getRepository().getConfig().getString("branch", | assertNull(localGit.getRepository().getConfig().getString("branch", | ||||
"newFromRemote", "remote")); | "newFromRemote", "remote")); |
Ref currentRef = repo.getRef(branchName); | Ref currentRef = repo.getRef(branchName); | ||||
if (currentRef == null) | if (currentRef == null) | ||||
continue; | continue; | ||||
if (currentRef.getName().equals(currentBranch)) | |||||
String fullName = currentRef.getName(); | |||||
if (fullName.equals(currentBranch)) | |||||
throw new CannotDeleteCurrentBranchException( | throw new CannotDeleteCurrentBranchException( | ||||
MessageFormat | MessageFormat | ||||
.format( | .format( | ||||
JGitText.get().cannotDeleteCheckedOutBranch, | JGitText.get().cannotDeleteCheckedOutBranch, | ||||
branchName)); | branchName)); | ||||
RefUpdate update = repo.updateRef(currentRef.getName()); | |||||
RefUpdate update = repo.updateRef(fullName); | |||||
update.setRefLogMessage("branch deleted", false); | update.setRefLogMessage("branch deleted", false); | ||||
update.setForceUpdate(true); | update.setForceUpdate(true); | ||||
Result deleteResult = update.delete(); | Result deleteResult = update.delete(); | ||||
} | } | ||||
if (ok) { | 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 | } else | ||||
throw new JGitInternalException(MessageFormat.format( | throw new JGitInternalException(MessageFormat.format( | ||||
JGitText.get().deleteBranchUnexpectedResult, | JGitText.get().deleteBranchUnexpectedResult, |