diff options
author | Zhen Chen <czhen@google.com> | 2017-07-20 17:20:55 -0700 |
---|---|---|
committer | Zhen Chen <czhen@google.com> | 2017-07-26 10:12:37 -0700 |
commit | b0695e5b7b639797280916201e49076784377bd5 (patch) | |
tree | c3404890d8a533fe218b6d5a16ac60fc221a517e /org.eclipse.jgit | |
parent | 673acfc6bdff0e339e47a7f950a44580fa74a637 (diff) | |
download | jgit-b0695e5b7b639797280916201e49076784377bd5.tar.gz jgit-b0695e5b7b639797280916201e49076784377bd5.zip |
Add commit check for head references
Make sure all refs/heads/* point to a commit object.
Change-Id: I9c7cf347aaf63d5ef604d520c2383c6cf3043890
Signed-off-by: Zhen Chen <czhen@google.com>
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/internal/fsck/FsckError.java | 7 | ||||
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsFsck.java | 8 |
2 files changed, 15 insertions, 0 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/fsck/FsckError.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/fsck/FsckError.java index b7aac1630b..588ed9bf8a 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/fsck/FsckError.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/fsck/FsckError.java @@ -128,6 +128,8 @@ public class FsckError { private final Set<CorruptIndex> corruptIndices = new HashSet<>(); + private final Set<String> nonCommitHeads = new HashSet<>(); + /** @return corrupt objects from all pack files. */ public Set<CorruptObject> getCorruptObjects() { return corruptObjects; @@ -142,4 +144,9 @@ public class FsckError { public Set<CorruptIndex> getCorruptIndices() { return corruptIndices; } + + /** @return refs/heads/* point to non-commit object. */ + public Set<String> getNonCommitHeads() { + return nonCommitHeads; + } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsFsck.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsFsck.java index 9549dbb2ea..f90ba7d986 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsFsck.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsFsck.java @@ -52,6 +52,7 @@ import org.eclipse.jgit.internal.fsck.FsckError; import org.eclipse.jgit.internal.fsck.FsckError.CorruptIndex; import org.eclipse.jgit.internal.fsck.FsckPackParser; import org.eclipse.jgit.internal.storage.pack.PackExt; +import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.ObjectChecker; import org.eclipse.jgit.lib.ProgressMonitor; import org.eclipse.jgit.lib.Ref; @@ -123,6 +124,13 @@ public class DfsFsck { for (Ref r : repo.getAllRefs().values()) { try { RevObject tip = ow.parseAny(r.getObjectId()); + if (r.getLeaf().getName().startsWith(Constants.R_HEADS)) { + // check if heads point to a commit object + if (tip.getType() != Constants.OBJ_COMMIT) { + errors.getNonCommitHeads() + .add(r.getLeaf().getName()); + } + } ow.markStart(tip); ow.checkConnectivity(); ow.markUninteresting(tip); |