-
Notifications
You must be signed in to change notification settings - Fork 533
Allow fetch operation to receive a ref
param
#362
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
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.
Can we add a test as well to show that the ref is properly added to the argument string?
lib/git/base.rb
Outdated
@@ -313,8 +313,8 @@ def checkout_file(version, file) | |||
|
|||
# fetches changes from a remote branch - this does not modify the working directory, | |||
# it just gets the changes from the remote if there are any | |||
def fetch(remote = 'origin', opts={}) | |||
self.lib.fetch(remote, opts) | |||
def fetch(remote = 'origin', ref = nil, opts={}) |
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.
This could potentially break implementations currently using #fetch
. For example,
g.fetch(origin, option: "something")
Will set remote
to origin
and ref
to { option: "something"}
Maybe we can utilize it inside of opts
?
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.
Good point, will look into this.
tests/units/test_remotes.rb
Outdated
second_commit = loc.log.first.sha | ||
|
||
# Make sure fetch message only has the first commit when we fetch the first commit | ||
assert(loc.fetch('origin', {:ref => first_commit}).include?(first_commit)) |
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.
Any thought on how to make this a little more robust?
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.
I think it might be more pertinent to test that the #command
method receives the expected argument strings, rather than testing the functionality of git from this high up.
Perhaps something like
assert_send(loc, :command, ["fetch", "origin", first_commit])
Some other considerations:
Can these refs be an array? What if I want to do this: (from git fetch's docs)
git fetch origin +pu:pu maint:tmp
This could be a future improvement.
I'm a little skeptical about using the name first_commit
, when it's actually just the sha. It might be more clear to the reader if you call it first_commit_sha
.
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.
Yeah, that's a bad name, I thought I'd use more than the sha, then I forgot to update the variable name.
I'll look into testing the #command
side of things, I wasn't super familiar with how best to accomplish that, so your example is really helpful
Also, refs could be an array, but I didn't take that into account. I'll see if that's easy to support, which I bet it is. If it's too annoying to add, I'll at least add a comment about the limitation.
Thanks for reviewing!!!
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.
Ok, so adding assert_send([loc.lib, :command, "fetch", ["origin", first_commit_sha]])
doesn't actually help test, as it passes as long as there isn't an error raised.
I think testing it from a high-level is probably #goodEnough
Normally I would just use expect(loc.lib).to receive(...)
if I were using rspec, but it seems like UnitTest is just not very featured when it comes to mocking.
Last commit folded my last comment: Ok, so adding Normally I would just use |
@taquitos sorry that was 100% my bad. I actually didn't know the actual method to use (I'm also a bit reliant on rspec for mocking) and spit out the closest thing I could find while Googling. Maybe it's something we can improve later. |
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.
Looks good, thanks! If you fix the stylistic issue I'll be happy to merge this.
lib/git/lib.rb
Outdated
@@ -738,6 +738,7 @@ def tag(name, *opts) | |||
|
|||
def fetch(remote, opts) | |||
arr_opts = [remote] | |||
arr_opts << opts[:ref] unless opts[:ref].nil? | |||
arr_opts << '--tags' if opts[:t] || opts[:tags] | |||
arr_opts << '--prune' if opts[:p] || opts[:prune] |
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.
I don't like us mixing unless foo.nil?
and if foo
syntax like this.
Are there any strong reasons why we couldn't rephrase this as:
arr_opts << opts[:ref] if opts[:ref]
The only semantic difference I can think of with these two forms is that the previous will let you pass in false
as a ref, but... that doesn't really make much sense anyway.
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.
No problem! I like the use of unless
to express the idea of We're going to add this, unless this thing is nil
. Of course your suggestion is totally reasonable: We're going to add this if there is something to add
. I updated the pr for the style changes 👍
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.
Thanks @taquitos. I agree that the unless pattern can make the code more readable, I just want things to be uniform.
@perlun ping 😄 |
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.
Thanks! Merging.
addresses #361