-
Notifications
You must be signed in to change notification settings - Fork 897
Add List Remote References without creating a Repository #1065
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@psawey 🆒 Some quick nitpicks:
|
@@ -1625,6 +1625,9 @@ IntPtr data | |||
|
|||
[DllImport(libgit2)] | |||
internal static extern int git_cherrypick(RepositorySafeHandle repo, GitObjectSafeHandle commit, GitCherryPickOptions options); | |||
|
|||
[DllImport(libgit2)] | |||
internal static extern int git_repository_new(out RepositorySafeHandle repo); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please move this next to the other git_repository_*
declarations?
Thoughts? |
@psawey Duh. I forgot about the #806 brought How about:
Another option may be to kill /cc @SimonCropp @dahlbyk |
Could |
The solution I'm looking at has |
@dahlbyk It would, may be better to |
👍 |
I would prefer an exception for remote It occurs to me that we don't support remote symbolic refs ( |
Currently, If I hack a ref with the command-line making it point to a non existing Oid, then load the ref through LibGit2Sharp, it doesn't throw. It returns null. Why wouldn't we keep the same behavior?
Is that a thing git.git really supports? (/cc @carlosmn)
|
Because in the "anonymous" repo situation it's strictly unnecessary, even incorrect, to use that property. There's nothing local to target. No need to conflate "you need to fetch" with "you cannot fetch".
Yup, try |
Sorry, I was unclear. Does
Ok. Sounds reasonable. But you'll have to provide the exception message to be used 😉 |
InvalidOperationException: Target|Repository requires a local repository. |
@psawey Could you please update your PR to reflect what has been discussed above? Regarding symbolic references handling, I'd rather keep that as a potential enhancement which would be dealt with in a separate PR. |
@carlosmn Does this rely on some magic guessing (finding a branch that points to the same oid than |
It does sometimes. The Git Smart Protocol lacked a way specify what the default branch actually was until fairly recently. What you'd do instead is get the id for HEAD and have to guess which one was the default branch. In case of tie, the first one wins, unless the master branch is in there, which always wins[0]. In order to fix this lack of control over which branch actually shows up when somebody clones, the protocol learnt a new extension, which lists the actual targets of the symrefs. As this is an extension, only newer gits understand this, so IIRC Ubuntu LTS ships with a version of git which does not understand this. We do understand this extension, and fill in the information in IMO trying to make this fit into a [0] This is in fact one of the very few places where 'master' is significantly relevant for git. |
Well really it should be shoving into a The other option is a new |
I've updated the PR with all suggestions above.
Returning a |
Would it make sense to use the same /// When the remote tips are ahead of the local ones, the retrieved
/// <see cref="DirectReference"/>s may point to non existing
/// <see cref="GitObject"/>s in the local repository. In that
/// case, <see cref="DirectReference.Target"/> will return <c>null</c>.
/// </para>
/// </summary>
/// <param name="remote">The <see cref="Remote"/> to list from.</param>
/// <param name="credentialsProvider">The <see cref="Func{Credentials}"/> used to connect to remote repository.</param>
/// <returns>The references in the <see cref="Remote"/> repository.</returns>
public virtual IEnumerable<DirectReference> ListReferences(Remote remote, CredentialsHandler credentialsProvider)
{ |
/// <summary> | ||
/// Reference to a Remote Head | ||
/// </summary> | ||
public class RemoteHead |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Drop this?
I think they're both fine as currently implemented. There's a useful distinction to me between unfetched (null) and couldn't-have-been fetched (missing repo). Revised API and tests look great to me. |
Whoops, yes, has been removed! |
get | ||
{ | ||
if (repo == null) | ||
throw new InvalidOperationException("Repository requires a local repository"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please wrap this in braces?
@psawey I'm very eager to see this merged! 👍 Last request: We tend to not merge review commits. Now that the review is done, could you please simplify the history and squash all those into one cohesive commit? |
@nulltoken Sure thing, will know for next time! |
Add List Remote References without creating a Repository
@psawey Amazing contribution! A thousand thanks for it! ✨ ✨ ✨ |
As mentioned #985, used git_repository_new() from the native side to implement this. Also introduced new public class RemoteHead as a container for the results.