libgit2/libgit2 — pull request #2174 by Yogu (2014-03-08 22:18:18+00:00)
Title: git_submodule_add_setup does not support relative urls

In git.git, you can clone a repository (e.g. `git clone git@github.com:libgit2/libgit2`) and then do `git submodule add ../libgit2sharp.git`. As this test points out, relative urls do not work in libgit2.

The problem is located in [lookup_head_remote](https://github.com/libgit2/libgit2/blame/development/src/submodule.c#L1455). It gets `HEAD` reference without resolving it, then tries to get the tracking branch of it - which obviously fails, because there is no tracking branch for `HEAD`. It might be a mistake to not dereference `HEAD`, but strangely, the method explicitly checks that `HEAD` is not a direct reference. Why that?

I tried to fix this by using `git_reference_lookup_resolved` and removing the first "Cannot resolve relative URL when HEAD is not symbolic" test, but then the same check fails for the resolved remote reference.

The top of the method summarizes:

/* 1. resolve HEAD -> refs/heads/BRANCH
* 2. lookup config branch.BRANCH.remote -> ORIGIN
* 3. lookup remote.ORIGIN.url
*/

but I think the method does something more compilcated. Honestly, I don't understand the method. Maybe @arrbee can look into this as he originally wrote the code.