Re: [PATCH JGIT] Circular references shouldn't be created
- From
Avery Pennarun <apenwarr@gmail.com>
- Date
- Sep 17, 2009, 21:40 UTC
- Message-ID
- <32541b130909171440w1a6d2394t4acc6a2f791c143@mail.gmail.com>
- In-Reply-To
- <C89280B882467443A695734861B942B28759DB95@DEWDFECCR09.wdf.sap.corp>
On Thu, Sep 17, 2009 at 3:23 PM, Sohn, Matthias <matthias.sohn@sap.com> wrote:
Show 5 quoted lines
> 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);This isn't a very thorough fix. It doesn't catch longer loops, like
HEAD -> chicken -> HEAD
or
a -> b -> c -> d -> a
Experimenting with original git.git's implementation, I see that this is allowed:
git symbolic-ref refs/heads/boink refs/heads/boink
It succeeds and creates a file that looks like this:
ref: refs/heads/boink
And "git show-ref refs/heads/boink" says: nothing (but returns an error code).
And "git log refs/heads/boink" says:
warning: ignoring dangling symref refs/heads/boink. fatal: ambiguous argument 'refs/heads/boink': unknown revision or path not in the working tree. Use '--' to separate paths from revisions
Clearly, in git.git, symref loops are caught at ref read time, not write time. This makes sense, since someone might foolishly twiddle the repository by hand and you don't want to get into an infinite loop in that case. Also, it's potentially useful to allow people to set invalid symrefs *temporarily*, as part of a multi step process.
Have fun,
Avery