public inbox for git@vger.kernel.org 
 help / color / mirror / Atom feed
* [PATCH JGIT] Circular references shouldn't be created
@ 2009-09-17 19:23 Sohn, Matthias
  2009-09-17 21:40 ` Avery Pennarun
  0 siblings, 1 reply; 5+ messages in thread
From: Sohn, Matthias @ 2009-09-17 19:23 UTC (permalink / raw)
  To: Shawn O. Pearce, Robin Rosenberg; +Cc: git@vger•kernel.org

From: Matthias Sohn <matthias.sohn@sap•com>
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@sap•com>
---
 .../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


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2009-09-18 21:20 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-09-17 19:23 [PATCH JGIT] Circular references shouldn't be created Sohn, Matthias
2009-09-17 21:40 ` Avery Pennarun
2009-09-17 22:51   ` Robin Rosenberg
2009-09-18  6:37     ` Sohn, Matthias
2009-09-18 21:20       ` Shawn O. Pearce

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox