Skip to content

Conversation

jimhester
Copy link
Contributor

Analogous to git ls-remote, returns all references from a remote
repository.

Fixes #130

I added documentation, tests and a note to NEWS. The libgit2 functions require a repository object to work, but the only information you really need for this is the remote URL. The interface allows you to pass a repository object if you want, otherwise it simply creates a temporary object in tempdir() and uses that.

Analogous to git ls-remote, returns all references from a remote
repository.
@stewid
Copy link
Member

stewid commented Sep 4, 2015

@jimhester thanks a lot!

I suggest we change the name to remote_ls to be consistent with the other remote methods: remote_add, remote_remove, remote_rename, remote_set_url and remote_url.

I take a closer look at the code later today.

@jimhester
Copy link
Contributor Author

👍 on remote_ls, the only reason I didn't do that to begin with was to match git ls-remote. I will add a mention of git ls-remote to the roxygen comment so it will show up in any future searches.

Copy link
Member

Choose a reason for hiding this comment

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

git2r_repository_open can return NULL and must be checked before usage, see https://github.com/ropensci/git2r/blob/master/src/git2r_remote.c#L54

if (!repository)
        git2r_error(git2r_err_invalid_repository, __func__, NULL);

- Rename to remote_ls
- Check result of git2r_repository_open
- Use err for error codes
- Explicitly assign to err so it can be used for printing error messages
- Allocate, assign and set names in one statement
- Move statements after all variable definitions
- Add optional credentials parameter
- Fix documentation typo
@jimhester
Copy link
Contributor Author

Ok 4a3187d should address all of your suggestions. Thank you for the review! Let me know if you see anything else that needs to be changed.

@jimhester
Copy link
Contributor Author

cd77539 is passing R CMD check without warnings, let me know if there is anything else you'd like changed, if not it should be ready to merge.

@stewid
Copy link
Member

stewid commented Sep 6, 2015

Thank you, I look at the code today.

Copy link
Member

Choose a reason for hiding this comment

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

Do we need to cleanup the temporary repository? One way could be to change the default repo argument to NULL and then something like this in the method:

path <- NULL
if (is.null(repo)) {
    path <- tempdir()
    repo <- git2r::init(path)
}

.Call(git2r_remote_ls, name, repo, credentials)

if (!is.null(path))
   unlink(path, recursive=TRUE)

What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The initial repository does not have a large size footprint and the tempdir will be removed when the R session ends, which is why I didn't clean it up explicitly. I added cleanup with jimhester@5b2067d

Copy link
Member

Choose a reason for hiding this comment

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

I like the usage of on.exit for the cleanup and also realize that my suggestion would actually fail to cleanup if .Call(...) fails.

stewid added a commit that referenced this pull request Sep 6, 2015
@stewid stewid merged commit 7612699 into ropensci:master Sep 6, 2015
@stewid
Copy link
Member

stewid commented Sep 6, 2015

Thanks for this PR 👍
I have added you to the git2r authors https://github.com/ropensci/git2r/blob/master/inst/AUTHORS

@jimhester
Copy link
Contributor Author

Great thanks, and thank you for the code review!

@sckott
Copy link
Contributor

sckott commented Oct 9, 2015

@stewid any way to do what ls_remote() does with current CRAN version? hoping to push up gistr version, and ideally need to check that a remote exists

@stewid
Copy link
Member

stewid commented Oct 10, 2015

@sckott no it only works with the development version. When do plan to push gistr?

@jimhester
Copy link
Contributor Author

If all you need to do is verify a remote is valid you could just try
fetching from it. That should return an error if it is not (which you can
catch)
On Oct 9, 2015 1:34 PM, "Scott Chamberlain" notifications@github.com
wrote:

@stewid https://github.com/stewid any way to do what ls_remote() does
with current CRAN version? hoping to push up gistr version, and ideally
need to check that a remote exists


Reply to this email directly or view it on GitHub
#172 (comment).

@sckott
Copy link
Contributor

sckott commented Oct 10, 2015

I already pushed it to CRAN - I did as @jimhester suggested, used tryCatch on push, then on failure, updated the remote.

@stewid
Copy link
Member

stewid commented Oct 10, 2015

Great

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.

3 participants