refspec: do not set empty rhs for fetch refspecs by pks-t · Pull Request #3882 · libgit2/libgit2 · GitHub
Skip to content

refspec: do not set empty rhs for fetch refspecs#3882

Merged
pks-t merged 1 commit into
libgit2:masterfrom
pks-t:pks/fix-fetch-refspec-dst-parsing
Sep 6, 2016
Merged

refspec: do not set empty rhs for fetch refspecs#3882
pks-t merged 1 commit into
libgit2:masterfrom
pks-t:pks/fix-fetch-refspec-dst-parsing

Conversation

@pks-t

@pks-t pks-t commented Aug 4, 2016

Copy link
Copy Markdown
Member

According to git-fetch(1), "[t]he colon can be omitted when
is empty." So according to git, the refspec "refs/heads/master"
is the same as the refspec "refs/heads/master:" when fetching
changes. When trying to fetch from a remote with a trailing
colon with libgit2, though, the fetch actually fails while it
works when the trailing colon is left out. So obviously, libgit2
does not treat these two refspec formats the same for fetches.

The problem results from parsing refspecs, where the resulting
refspec has its destination set to an empty string in the case of
a trailing colon and to a NULL pointer in the case of no
trailing colon. When passing this to our DWIM machinery, the
empty string gets translated to "refs/heads/", which is simply
wrong.

Fix the problem by having the parsing machinery treat both cases
the same for fetch refspecs.

According to git-fetch(1), "[t]he colon can be omitted when <dst>
is empty." So according to git, the refspec "refs/heads/master"
is the same as the refspec "refs/heads/master:" when fetching
changes. When trying to fetch from a remote with a trailing
colon with libgit2, though, the fetch actually fails while it
works when the trailing colon is left out. So obviously, libgit2
does _not_ treat these two refspec formats the same for fetches.

The problem results from parsing refspecs, where the resulting
refspec has its destination set to an empty string in the case of
a trailing colon and to a `NULL` pointer in the case of no
trailing colon. When passing this to our DWIM machinery, the
empty string gets translated to "refs/heads/", which is simply
wrong.

Fix the problem by having the parsing machinery treat both cases
the same for fetch refspecs.
@pks-t

pks-t commented Aug 4, 2016

Copy link
Copy Markdown
Member Author

@pks-t

pks-t commented Aug 29, 2016

Copy link
Copy Markdown
Member Author

@pks-t pks-t merged commit 46035d9 into libgit2:master Sep 6, 2016
@pks-t pks-t deleted the pks/fix-fetch-refspec-dst-parsing branch October 10, 2016 07:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant