From: Matthias Sohn <matthias.sohn@xxxxxxx> Circular references shouldn't be created Fix for bug: https://bugs.eclipse.org/bugs/show_bug.cgi?id=286743 Signed-off-by: Matthias Sohn <matthias.sohn@xxxxxxx> --- .../tst/org/spearce/jgit/lib/RefTest.java | 9 +++++++++ .../src/org/spearce/jgit/lib/RefDatabase.java | 4 ++++ 2 files changed, 13 insertions(+), 0 deletions(-) diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/RefTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/RefTest.java index fabbe7e..ce6328b 100644 --- a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/RefTest.java +++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/RefTest.java @@ -155,4 +155,13 @@ public void testOrigResolvedNamesSymRef() throws IOException { assertEquals("refs/heads/master", ref.getName()); assertEquals("HEAD", ref.getOrigName()); } + + public void testIllegalCircularRef() throws IOException { + try { + db.writeSymref("HEAD", "HEAD"); + fail("creation of circular reference should fail"); + } catch (IllegalArgumentException expected) { + // attempt to create circular reference should fail + } + } } diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/RefDatabase.java b/org.spearce.jgit/src/org/spearce/jgit/lib/RefDatabase.java index 09cb9bb..483b1d0 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/lib/RefDatabase.java +++ b/org.spearce.jgit/src/org/spearce/jgit/lib/RefDatabase.java @@ -174,6 +174,10 @@ RefRename newRename(String fromRef, String toRef) throws IOException { * @throws IOException */ void link(final String name, final String target) throws IOException { + if (name.equals(target)) + throw new IllegalArgumentException( + "illegal circular reference : symref " + name + + " cannot refer to " + target); final byte[] content = Constants.encode("ref: " + target + "\n"); lockAndWriteFile(fileForRef(name), content); synchronized (this) { -- 1.6.4.msysgit.0 ��.n��������+%������w��{.n��������n�r������&��z�ޗ�zf���h���~����������_��+v���)ߣ�m