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

Implement porcelain describe #55

Merged

Conversation

betesh
Copy link
Contributor

@betesh betesh commented Apr 30, 2020

I intend to implement grep as well, following https://stackoverflow.com/questions/15572483/how-to-do-git-grep-e-pattern-with-jgit/16263886#16263886.

It's going to be more work than describe was, so before I move forward, could a maintainer please tell me 1) whether the project would accept such an addition? and 2) whether it should be on a separate branch?

Thank you!

@betesh betesh force-pushed the implement-porcelain-describe-and-grep branch from 199f0bd to b5d64d4 Compare April 30, 2020 01:24
@coveralls
Copy link

coveralls commented Apr 30, 2020

Coverage Status

Coverage increased (+0.009%) to 99.379% when pulling 7c0a62b on betesh:implement-porcelain-describe-and-grep into d718812 on repotag:master.

Copy link
Contributor

@bartkamphorst bartkamphorst left a comment

Choose a reason for hiding this comment

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

Thanks @betesh for the PR! We're happy with the help and will be happy to add Porcelain.describe. A few points still to address though, see the review remarks.

lib/rjgit.rb Outdated
options = {:always => false, :long => false, :tags => false}.merge(options)
repo = RJGit.repository_type(repository)
git = RubyGit.new(repo).jgit
git.describe.set_target(ref).set_always(options[:always]).set_long(options[:long]).set_tags(options[:tags]).call
Copy link
Contributor

Choose a reason for hiding this comment

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

This line (ending in .call) should be wrapped in a begin rescue end block and rescue the exceptions that DescribeCommand can throw (i.e., MissingObjectException, IncorrectObjectTypeException, RefNotFoundException, IOException).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

how should it handle those exceptions? return nil? raise a Ruby exception of some type (what type)?

Copy link
Contributor

Choose a reason for hiding this comment

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

Returning nil would be fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

lib/rjgit.rb Show resolved Hide resolved
@@ -170,6 +170,11 @@
end
end

it "mimics git-describe" do
Copy link
Contributor

Choose a reason for hiding this comment

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

Please also add tests for negative cases (wrong input, or no no names found, etc.).

@bartkamphorst
Copy link
Contributor

Regarding grep functionality: the gollum RJGit adapter implements grepping here leveraging RJGit::Porcelain.ls_tree. @dometto Any thoughts on such an approach for RJGit itself? Or would you prefer the approach @betesh referenced in this StackOverflow issue?

@dometto
Copy link
Contributor

dometto commented Apr 30, 2020

Regarding grep: I think I wrote that function for gollum because I thought it would be a) simpler than adding support for JGit's grep to RJGit and b) gollum also wants to match pathname, not just file contents. But support for grep in RJGit would not conflict with that, and I'm all for it! Thanks for chipping in, @betesh!

@betesh
Copy link
Contributor Author

betesh commented Apr 30, 2020

@dometto It seems like your implementation is much more straightforward? Why not just copy-and-paste it into this repo? (I don't mind writing a few tests, but as far as the code itself, it makes more sense to me for you to push the commit and keep your name on it than for me to paste it and attribute you, especially considering that your LICENSE is empty.)

@dometto
Copy link
Contributor

dometto commented May 1, 2020

@betesh I'm fine with using the code from the adapter to implement grep, since JGit doesn't have its own GrepCommand anyway. @bartkamphorst how do you feel about it?

We should add a LICENSE file for sure, but I am not really worried about the attribution, especially since some lines in the snippet would have to be changed/removed anyway (thinking of the Gollum::Git.canonicalize and yield calls for example -- although maybe we could keep the yield as an option?). If you're willing to put in the time to 'port' it to RJGit and write some specs, that would be much appreciated!

@bartkamphorst
Copy link
Contributor

I'm okay with using the adapter code as a basis for the actual implementation. 👍

@betesh
Copy link
Contributor Author

betesh commented May 4, 2020

@bartkamphorst Do you want to merge this and then I'll tackle grep in a separate PR?

@bartkamphorst
Copy link
Contributor

@bartkamphorst Do you want to merge this and then I'll tackle grep in a separate PR?

I have one more suggestion for a minor refactoring, but otherwise it's looking good. Tackling grep in a separate PR is the right way to go. Thanks! 👍

@betesh betesh changed the title Implement porcelain describe and grep Implement porcelain describe May 6, 2020
@bartkamphorst bartkamphorst merged commit 0589b42 into repotag:master May 7, 2020
@betesh betesh deleted the implement-porcelain-describe-and-grep branch May 7, 2020 13:41
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.

4 participants