Parcourir la source

Don't print "into HEAD" when merging refs/heads/master

When MergeMessageFormatter was given a symbolic ref HEAD which points to
refs/heads/master (which is the case when merging a branch in EGit), it
would result in a merge message like the following:

  Merge branch 'a' into HEAD

But it should print the following (as C Git does):

  Merge branch 'a'

The solution is to use the leaf ref when checking for refs/heads/master.

Change-Id: I28ae5713b7e8123a0176fc6d7356e469900e7e97
tags/v0.11.1
Robin Stocker il y a 13 ans
Parent
révision
b0245b548b

+ 10
- 0
org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/MergeMessageFormatterTest.java Voir le fichier

import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectIdRef; import org.eclipse.jgit.lib.ObjectIdRef;
import org.eclipse.jgit.lib.Ref; import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.SymbolicRef;
import org.eclipse.jgit.lib.Ref.Storage; import org.eclipse.jgit.lib.Ref.Storage;
import org.eclipse.jgit.lib.RefUpdate; import org.eclipse.jgit.lib.RefUpdate;
import org.eclipse.jgit.lib.SampleDataRepositoryTestCase; import org.eclipse.jgit.lib.SampleDataRepositoryTestCase;
String message = formatter.format(Arrays.asList(a), b); String message = formatter.format(Arrays.asList(a), b);
assertEquals("Merge branch 'a' into b", message); assertEquals("Merge branch 'a' into b", message);
} }

@Test
public void testIntoSymbolicRefHeadPointingToMaster() throws IOException {
Ref a = db.getRef("refs/heads/a");
Ref master = db.getRef("refs/heads/master");
SymbolicRef head = new SymbolicRef("HEAD", master);
String message = formatter.format(Arrays.asList(a), head);
assertEquals("Merge branch 'a'", message);
}
} }

+ 2
- 1
org.eclipse.jgit/src/org/eclipse/jgit/merge/MergeMessageFormatter.java Voir le fichier



sb.append(StringUtils.join(listings, ", ")); sb.append(StringUtils.join(listings, ", "));


if (!target.getName().equals(Constants.R_HEADS + Constants.MASTER)) {
String targetName = target.getLeaf().getName();
if (!targetName.equals(Constants.R_HEADS + Constants.MASTER)) {
String targetShortName = Repository String targetShortName = Repository
.shortenRefName(target.getName()); .shortenRefName(target.getName());
sb.append(" into " + targetShortName); sb.append(" into " + targetShortName);

Chargement…
Annuler
Enregistrer