Skip to content
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

remotes: support anonymous remotes #1229

Merged
merged 1 commit into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pygit2/decl/remote.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ int git_remote_create_with_fetchspec(
const char *name,
const char *url,
const char *fetch);
int git_remote_create_anonymous(
git_remote **out,
git_repository *repo,
const char *url);
int git_remote_delete(git_repository *repo, const char *name);
const char * git_remote_name(const git_remote *remote);
int git_remote_rename(
Expand Down
10 changes: 10 additions & 0 deletions pygit2/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,16 @@ def create(self, name, url, fetch=None):

return Remote(self._repo, cremote[0])

def create_anonymous(self, url):
"""Create a new anonymous (in-memory only) remote with the given URL.
Returns a <Remote> object.
"""
Comment on lines +347 to +350
Copy link
Contributor Author

@pmrowla pmrowla Jul 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be done in the existing create() by checking something like

if not name:
    C.git_remote_create_anonymous()

but I wasn't sure if that would be explicit enough since create(None, url) could also imply that the user intended to make a libgit2 detached remote instead of an anonymous one. (Or we could also do it with create(None, url, anonymous=True))

Adding the separate method seemed like the cleanest solution to me, but I don't have a problem with changing it to one of the alternatives if you'd prefer.

cremote = ffi.new('git_remote **')
url = to_bytes(url)
err = C.git_remote_create_anonymous(cremote, self._repo._repo, url)
check_error(err)
return Remote(self._repo, cremote[0])

def rename(self, name, new_name):
"""Rename a remote in the configuration. The refspecs in standard
format will be renamed.
Expand Down
10 changes: 10 additions & 0 deletions test/test_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ def test_remote_create_with_refspec(testrepo):
assert [fetch] == remote.fetch_refspecs
assert remote.push_url is None

def test_remote_create_anonymous(testrepo):
url = 'https://github.com/libgit2/pygit2.git'

remote = testrepo.remotes.create_anonymous(url)
assert remote.name is None
assert url == remote.url
assert remote.push_url is None
assert [] == remote.fetch_refspecs
assert [] == remote.push_refspecs

def test_remote_delete(testrepo):
name = 'upstream'
url = 'https://github.com/libgit2/pygit2.git'
Expand Down
Loading