Skip to content

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

Merged
merged 8 commits into from
Jun 25, 2018
Merged

Allow fetch operation to receive a ref param #362

merged 8 commits into from
Jun 25, 2018

Conversation

taquitos
Copy link
Contributor

@taquitos taquitos commented Apr 19, 2018

addresses #361

Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the
    best of my knowledge, is covered under an appropriate open
    source license and I have the right under that license to   
    submit that work with modifications, whether created in whole
    or in part by me, under the same open source license (unless
    I am permitted to submit under a different license), as
    Indicated in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including
    all personal information I submit with it, including my
    sign-off) is maintained indefinitely and may be redistributed
    consistent with this project or the open source license(s)
    involved.

Copy link

@kylemacey kylemacey left a 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={})

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?

Copy link
Contributor Author

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.

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))
Copy link
Contributor Author

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?

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.

Copy link
Contributor Author

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!!!

Copy link
Contributor Author

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.

@taquitos
Copy link
Contributor Author

Last commit folded my last comment:

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.

@kylemacey
Copy link

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.

@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.

@kylemacey
Copy link

@perlun @tarcinil want to give this a final 👍?

Copy link
Contributor

@perlun perlun left a 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]
Copy link
Contributor

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.

Copy link
Contributor Author

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 👍

Copy link
Contributor

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.

@taquitos
Copy link
Contributor Author

@perlun ping 😄

Copy link
Contributor

@perlun perlun left a comment

Choose a reason for hiding this comment

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

Thanks! Merging.

@perlun perlun merged commit e7f1880 into ruby-git:master Jun 25, 2018
@taquitos taquitos deleted the custom_fetch branch June 25, 2018 19:00
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