Merge "Disallow deletion of HEAD and targets of symbolic refs"
This commit is contained in:
@@ -35,8 +35,10 @@ import java.io.IOException;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
class ListBranches extends Handler<ListBranchesResult> {
|
class ListBranches extends Handler<ListBranchesResult> {
|
||||||
interface Factory {
|
interface Factory {
|
||||||
@@ -67,6 +69,7 @@ class ListBranches extends Handler<ListBranchesResult> {
|
|||||||
|
|
||||||
final List<Branch> branches = new ArrayList<Branch>();
|
final List<Branch> branches = new ArrayList<Branch>();
|
||||||
Branch headBranch = null;
|
Branch headBranch = null;
|
||||||
|
final Set<String> targets = new HashSet<String>();
|
||||||
|
|
||||||
final Repository db;
|
final Repository db;
|
||||||
try {
|
try {
|
||||||
@@ -92,6 +95,12 @@ class ListBranches extends Handler<ListBranchesResult> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (final Ref ref : all.values()) {
|
||||||
|
if (ref.isSymbolic()) {
|
||||||
|
targets.add(ref.getTarget().getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (final Ref ref : all.values()) {
|
for (final Ref ref : all.values()) {
|
||||||
if (ref.isSymbolic()) {
|
if (ref.isSymbolic()) {
|
||||||
// A symbolic reference to another branch, instead of
|
// A symbolic reference to another branch, instead of
|
||||||
@@ -108,11 +117,12 @@ class ListBranches extends Handler<ListBranchesResult> {
|
|||||||
|
|
||||||
Branch b = createBranch(ref.getName());
|
Branch b = createBranch(ref.getName());
|
||||||
b.setRevision(new RevId(target));
|
b.setRevision(new RevId(target));
|
||||||
b.setCanDelete(targetRefControl.canDelete());
|
|
||||||
|
|
||||||
if (Constants.HEAD.equals(ref.getName())) {
|
if (Constants.HEAD.equals(ref.getName())) {
|
||||||
|
b.setCanDelete(false);
|
||||||
headBranch = b;
|
headBranch = b;
|
||||||
} else {
|
} else {
|
||||||
|
b.setCanDelete(targetRefControl.canDelete());
|
||||||
branches.add(b);
|
branches.add(b);
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
@@ -127,7 +137,7 @@ class ListBranches extends Handler<ListBranchesResult> {
|
|||||||
b.setRevision(new RevId(ref.getObjectId().name()));
|
b.setRevision(new RevId(ref.getObjectId().name()));
|
||||||
}
|
}
|
||||||
|
|
||||||
b.setCanDelete(refControl.canDelete());
|
b.setCanDelete(!targets.contains(ref.getName()) && refControl.canDelete());
|
||||||
|
|
||||||
branches.add(b);
|
branches.add(b);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user