|
|
@ -43,16 +43,18 @@ |
|
|
|
|
|
|
|
|
|
|
|
package org.eclipse.jgit.pgm; |
|
|
|
package org.eclipse.jgit.pgm; |
|
|
|
|
|
|
|
|
|
|
|
import static org.eclipse.jgit.lib.RefDatabase.ALL; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
|
import java.io.IOException; |
|
|
|
import java.text.MessageFormat; |
|
|
|
import java.text.MessageFormat; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.ArrayList; |
|
|
|
|
|
|
|
import java.util.Collection; |
|
|
|
import java.util.LinkedHashMap; |
|
|
|
import java.util.LinkedHashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Map.Entry; |
|
|
|
import java.util.Map.Entry; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.eclipse.jgit.api.Git; |
|
|
|
|
|
|
|
import org.eclipse.jgit.api.ListBranchCommand; |
|
|
|
|
|
|
|
import org.eclipse.jgit.api.ListBranchCommand.ListMode; |
|
|
|
import org.eclipse.jgit.lib.Constants; |
|
|
|
import org.eclipse.jgit.lib.Constants; |
|
|
|
import org.eclipse.jgit.lib.ObjectId; |
|
|
|
import org.eclipse.jgit.lib.ObjectId; |
|
|
|
import org.eclipse.jgit.lib.ObjectReader; |
|
|
|
import org.eclipse.jgit.lib.ObjectReader; |
|
|
@ -60,8 +62,8 @@ import org.eclipse.jgit.lib.Ref; |
|
|
|
import org.eclipse.jgit.lib.RefComparator; |
|
|
|
import org.eclipse.jgit.lib.RefComparator; |
|
|
|
import org.eclipse.jgit.lib.RefRename; |
|
|
|
import org.eclipse.jgit.lib.RefRename; |
|
|
|
import org.eclipse.jgit.lib.RefUpdate; |
|
|
|
import org.eclipse.jgit.lib.RefUpdate; |
|
|
|
import org.eclipse.jgit.lib.Repository; |
|
|
|
|
|
|
|
import org.eclipse.jgit.lib.RefUpdate.Result; |
|
|
|
import org.eclipse.jgit.lib.RefUpdate.Result; |
|
|
|
|
|
|
|
import org.eclipse.jgit.lib.Repository; |
|
|
|
import org.eclipse.jgit.pgm.internal.CLIText; |
|
|
|
import org.eclipse.jgit.pgm.internal.CLIText; |
|
|
|
import org.eclipse.jgit.pgm.opt.CmdLineParser; |
|
|
|
import org.eclipse.jgit.pgm.opt.CmdLineParser; |
|
|
|
import org.eclipse.jgit.revwalk.RevWalk; |
|
|
|
import org.eclipse.jgit.revwalk.RevWalk; |
|
|
@ -78,6 +80,9 @@ class Branch extends TextBuiltin { |
|
|
|
@Option(name = "--all", aliases = { "-a" }, usage = "usage_listBothRemoteTrackingAndLocalBranches") |
|
|
|
@Option(name = "--all", aliases = { "-a" }, usage = "usage_listBothRemoteTrackingAndLocalBranches") |
|
|
|
private boolean all = false; |
|
|
|
private boolean all = false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Option(name = "--contains", metaVar = "metaVar_commitish", usage = "usage_printOnlyBranchesThatContainTheCommit") |
|
|
|
|
|
|
|
private String containsCommitish; |
|
|
|
|
|
|
|
|
|
|
|
@Option(name = "--delete", aliases = { "-d" }, usage = "usage_deleteFullyMergedBranch") |
|
|
|
@Option(name = "--delete", aliases = { "-d" }, usage = "usage_deleteFullyMergedBranch") |
|
|
|
private boolean delete = false; |
|
|
|
private boolean delete = false; |
|
|
|
|
|
|
|
|
|
|
@ -177,15 +182,27 @@ class Branch extends TextBuiltin { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void list() throws Exception { |
|
|
|
private void list() throws Exception { |
|
|
|
Map<String, Ref> refs = db.getRefDatabase().getRefs(ALL); |
|
|
|
Ref head = db.getRef(Constants.HEAD); |
|
|
|
Ref head = refs.get(Constants.HEAD); |
|
|
|
|
|
|
|
// This can happen if HEAD is stillborn
|
|
|
|
// This can happen if HEAD is stillborn
|
|
|
|
if (head != null) { |
|
|
|
if (head != null) { |
|
|
|
String current = head.getLeaf().getName(); |
|
|
|
String current = head.getLeaf().getName(); |
|
|
|
if (current.equals(Constants.HEAD)) |
|
|
|
ListBranchCommand command = new Git(db).branchList(); |
|
|
|
addRef("(no branch)", head); //$NON-NLS-1$
|
|
|
|
if (all) |
|
|
|
addRefs(refs, Constants.R_HEADS, !remote); |
|
|
|
command.setListMode(ListMode.ALL); |
|
|
|
addRefs(refs, Constants.R_REMOTES, remote); |
|
|
|
else if (remote) |
|
|
|
|
|
|
|
command.setListMode(ListMode.REMOTE); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (containsCommitish != null) |
|
|
|
|
|
|
|
command.setContains(containsCommitish); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<Ref> refs = command.call(); |
|
|
|
|
|
|
|
for (Ref ref : refs) { |
|
|
|
|
|
|
|
if (ref.getName().equals(Constants.HEAD)) |
|
|
|
|
|
|
|
addRef("(no branch)", head); //$NON-NLS-1$
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
addRefs(refs, Constants.R_HEADS); |
|
|
|
|
|
|
|
addRefs(refs, Constants.R_REMOTES); |
|
|
|
|
|
|
|
|
|
|
|
ObjectReader reader = db.newObjectReader(); |
|
|
|
ObjectReader reader = db.newObjectReader(); |
|
|
|
try { |
|
|
|
try { |
|
|
@ -200,14 +217,11 @@ class Branch extends TextBuiltin { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void addRefs(final Map<String, Ref> allRefs, final String prefix, |
|
|
|
private void addRefs(final Collection<Ref> refs, final String prefix) { |
|
|
|
final boolean add) { |
|
|
|
for (final Ref ref : RefComparator.sort(refs)) { |
|
|
|
if (all || add) { |
|
|
|
final String name = ref.getName(); |
|
|
|
for (final Ref ref : RefComparator.sort(allRefs.values())) { |
|
|
|
if (name.startsWith(prefix)) |
|
|
|
final String name = ref.getName(); |
|
|
|
addRef(name.substring(name.indexOf('/', 5) + 1), ref); |
|
|
|
if (name.startsWith(prefix)) |
|
|
|
|
|
|
|
addRef(name.substring(name.indexOf('/', 5) + 1), ref); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|