git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH JGIT] Circular references shouldn't be created

From
Sohn, Matthias <matthias.sohn@sap.com>
Date
Sep 17, 2009, 19:23 UTC
Message-ID
<C89280B882467443A695734861B942B28759DB95@DEWDFECCR09.wdf.sap.corp>
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
Next: Avery Pennarun
Message 1 of 5 in “Circular references shouldn't be created”
  1. Circular references shouldn't be createdSohn, Matthias, Sep 17, 2009
  2. Avery PennarunSep 17, 2009
  3. Robin RosenbergSep 17, 2009
  4. Sohn, MatthiasSep 18, 2009
  5. Shawn O. PearceSep 18, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.