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

Refactor LibGit2.set_remote_url #22062

Merged
merged 3 commits into from
Jun 7, 2017
Merged

Refactor LibGit2.set_remote_url #22062

merged 3 commits into from
Jun 7, 2017

Conversation

omus
Copy link
Member

@omus omus commented May 25, 2017

Added new functions set_remote_fetch_url and set_remote_push_url which allow you to specify the fetch/push remote URLs independently. Additionally, I switched set_remote_url from using a the keyword remote to using an optional argument.

Fixes #21773

@omus omus added the libgit2 The libgit2 library or the LibGit2 stdlib module label May 25, 2017
if push != url
set!(cfg, "remote.$remote.pushurl", push)
end
end
Copy link
Member Author

Choose a reason for hiding this comment

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

Caused #21773

@omus omus requested a review from kshyatt May 25, 2017 20:52
@StefanKarpinski
Copy link
Member

Feature or bugfix?

@tkelman
Copy link
Contributor

tkelman commented May 25, 2017

looks like a little of both, plus a new deprecation

repo_path = joinpath("test_directory", "Example")
repo = LibGit2.init(repo_path)
url1 = "https://github.com/JuliaLang/Example.jl"
LibGit2.set_remote_url(repo, url1, remote="upstream")
Copy link
Contributor

Choose a reason for hiding this comment

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

bit misleading to name the argument at the call site if it's positional

Copy link
Member Author

Choose a reason for hiding this comment

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

I missed this when I moved away from a keyword.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed

if remote_kwarg === nothing
return remote_arg
else
msg = "$f($sig; remote=\"$remote_kwarg\") is deprecated, use $f($sig, \"$remote_kwarg\")"
Copy link
Contributor

Choose a reason for hiding this comment

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

these usually end with "instead"

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok. I modeled this off of the deprecate_negate function. Does the rest of this seem reasonable?

Copy link
Contributor

Choose a reason for hiding this comment

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

I wrote that one, and went through a couple refactors of it. it does say instead in it.

the argument order differs from the libgit2 c functions', but I guess that's okay. positionals always run the risk of "what order is it supposed to be" when writing or reading code that uses the method, so I'm neutral on this part of the change

Copy link
Member Author

Choose a reason for hiding this comment

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

I modeled this off of the deprecate_negate function. Does the rest of this seem reasonable?

I should have been more specific. I was wondering if the deprecate_remote_keyword function was reasonable.

Copy link
Member Author

Choose a reason for hiding this comment

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

the argument order differs from the libgit2 c functions'

Re-ordering the functions to be func(repo::GitRepo, remote::AbstractString, url::AbstractString) would more closely match both LibGit2 and the git command line. Personally I am fine with always having to specify the remote name.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

test/libgit2.jl Outdated
@@ -37,6 +37,15 @@ function with_libgit2_temp_home(f)
end
end

function is_defined_remote(repo::LibGit2.GitRepo, remote::AbstractString)
try
LibGit2.get(LibGit2.GitRemote, repo, name)
Copy link
Contributor

Choose a reason for hiding this comment

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

can this be done without try-catching?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll look into this again tomorrow. I didn't find a LibGit2 method which seemed to cover this.

Copy link
Member Author

Choose a reason for hiding this comment

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

Made lookup_remote to address this

test/libgit2.jl Outdated
@test !is_defined_remote(repo, name)

# Set just the fetch URL
LibGit2.set_remote_fetch_url(repo, url, name)
Copy link
Contributor

Choose a reason for hiding this comment

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

this is testing the repo::GitRepo versions pretty well, and the existing block was testing some of the path::AbstractString versions, but not the ones you're newly adding

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll extend the tests to cover those.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@omus
Copy link
Member Author

omus commented May 26, 2017

Feature or bugfix?

Definitely both. When addressing the bug I noticed that the GitConfig was being used to modify the remote rather than using the available LibGit2 functions. Using the config method is bad as it doesn't verify that things like the remote name is valid. After getting my hands into the code I noticed that the remote keyword was unnecessary which is how I ended up here.

@omus
Copy link
Member Author

omus commented May 26, 2017

I'll add some docstrings to the new functions in addition to the review change requests.

@StefanKarpinski
Copy link
Member

I guess what I was getting at was is this backportable to 0.6 or does it need to stay on master?

@omus
Copy link
Member Author

omus commented May 26, 2017

I guess what I was getting at was is this backportable to 0.6 or does it need to stay on master?

I can separate the bugfix so it can be backported to 0.6.

@omus
Copy link
Member Author

omus commented May 26, 2017

A note for the future @tkelman: Only backport commit d4a43e4

@omus omus force-pushed the cv/set-remote branch 3 times, most recently from 29fb185 to 729f891 Compare May 29, 2017 15:41
@omus
Copy link
Member Author

omus commented Jun 5, 2017

Anything left to do here? Maybe a NEWS entry?

function set_remote_push_url end

function set_remote_push_url(repo::GitRepo, remote_name::AbstractString, url::AbstractString)
@check ccall((:git_remote_set_pushurl, :libgit2), Cint,
Copy link
Contributor

Choose a reason for hiding this comment

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

under-indented

Copy link
Member Author

Choose a reason for hiding this comment

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

Nice catch

omus added 2 commits June 6, 2017 10:44
When using `LibGit2.set_remote_url` to specify a GitHub HTTP URL only
the fetch URL would be modified to use HTTP and the push URL would
always be set to SSH.
Changes include:
- Creating `set_remote_fetch_url`, `set_remote_push_url`,
  `remote_delete`, and `lookup_remote`
- Updating `set_remote_url` to use LibGit2 calls
- Deprecate `set_remote_url` which uses keyword and reorder arguments to
  match order of `GitRemote` constructor.
- Update all existing calls to `set_remote_url`
@omus
Copy link
Member Author

omus commented Jun 6, 2017

Rebased to resolve conflict in "base/deprecated.jl"

@omus
Copy link
Member Author

omus commented Jun 6, 2017

Ready for merge

@tkelman
Copy link
Contributor

tkelman commented Jun 7, 2017

didn't add a news entry, were you going to?

@omus
Copy link
Member Author

omus commented Jun 7, 2017

I wasn't planning on adding one but I will now.

[ci skip]
@omus
Copy link
Member Author

omus commented Jun 7, 2017

NEWS entry added.

@omus omus merged commit 13c1830 into master Jun 7, 2017
@omus omus deleted the cv/set-remote branch June 7, 2017 20:22
tkelman pushed a commit that referenced this pull request Jun 17, 2017
When using `LibGit2.set_remote_url` to specify a GitHub HTTP URL only
the fetch URL would be modified to use HTTP and the push URL would
always be set to SSH.

(cherry picked from commit d4a43e4)
partial backport of #22062
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libgit2 The libgit2 library or the LibGit2 stdlib module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants