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

Using default pager in gh pr diff #1534

Merged
merged 1 commit into from
Aug 19, 2020

Conversation

mmontes11
Copy link
Contributor

@mmontes11 mmontes11 commented Aug 15, 2020

Closes #1100

Changes:

  • Using user's default pager for displaying PR diffs by checking PAGER env variable
  • If no pager is configured it works as before

Steps for testing this PR:

  • export PAGER='less -R';
  • Run gh pr diff <pr-id>

@mmontes11 mmontes11 marked this pull request as ready for review August 15, 2020 13:11
Copy link
Contributor

@mislav mislav left a comment

Choose a reason for hiding this comment

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

Thank you for your contribution! This looks like a great start. Once we resolve the discussion points I left in the comments, the final thing I would request is a test for cases where a pager is used or not. 🙇

pkg/cmd/pr/diff/diff.go Outdated Show resolved Hide resolved
@@ -134,3 +142,26 @@ func isRemovalLine(dl string) bool {
func validColorFlag(c string) bool {
return c == "auto" || c == "always" || c == "never"
}

func getDefaultPager() (string, error) {
getPagerCmd := git.GitCommand("config", "--get", "core.pager")
Copy link
Contributor

Choose a reason for hiding this comment

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

Respecting git's core.pager is something that I feel warrants discussion. On one hand, this might feel like the right thing to do in gh pr diff since it feels so much like git diff. On the other hand, at no point do we actually invoke git diff, so I don't feel strongly that we should support any of git's configuration around diffing and paging. In fact, instead of respecting git config core.pager or GIT_PAGER, I think we should only respect the PAGER environment variable.

@vilmibm Thoughts?

Copy link
Contributor Author

@mmontes11 mmontes11 Aug 17, 2020

Choose a reason for hiding this comment

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

I agree with @mislav that using core.pager for this can be weird. Also, using PAGER env variable makes testability of this feature easier, since we can mock that variable in tests!

@mmontes11 mmontes11 force-pushed the pr-diff-use-default-pager branch 3 times, most recently from b75e70a to 2ca3e24 Compare August 17, 2020 17:30
Copy link
Contributor

@mislav mislav left a comment

Choose a reason for hiding this comment

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

Thank you for the fast update!

pkg/cmd/pr/diff/diff.go Outdated Show resolved Hide resolved
Copy link
Contributor

@mislav mislav 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 to me! BTW, when going through rounds of review-and-update with someone, it's helpful for the person reviewing (me) if you refrain from force-pushing so I can use the diff features to see only the changes from my last review. If there are too many messy commits in the branch, you can rebase it once we're all done with reviewing, or we will squash the whole thing when we merge 👍

Curious what @vilmibm has to say

os.Setenv("PAGER", pager)
http.Verify(t)
}()
runPager = func(pager string, diff io.Reader, out io.Writer) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

Note for @vilmibm: instead of overriding runPager here, maybe we could let it shell out to a real binary which is the go test binary, similar to what you've done for stubbing out shelling out to commands in the past? I feel like it would be an ideal case to bring back that approach

Copy link
Contributor

Choose a reason for hiding this comment

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

I took that out because it was a difficult to debug hack...I think this is sufficient coverage for now. I'm guessing your concern is from the package level stubbing?

I'd rather see us step back and design a way to have factories send in external program callers.

@mmontes11
Copy link
Contributor Author

My fault @mislav, next time will do the commit surgery after the rounds of review-and-update so you have a clear history. Thanks for the detailed feedback 🙏

@vilmibm
Copy link
Contributor

vilmibm commented Aug 17, 2020

thank you!

@vilmibm vilmibm added this to Backlog 🗒 in The GitHub CLI via automation Aug 19, 2020
@vilmibm vilmibm moved this from Backlog 🗒 to Needs to be merged 🎉 in The GitHub CLI Aug 19, 2020
@vilmibm vilmibm merged commit 88b5a3b into cli:trunk Aug 19, 2020
The GitHub CLI automation moved this from Needs to be merged 🎉 to Pending Release 🥚 Aug 19, 2020
@github-actions github-actions bot moved this from Pending Release 🥚 to Done 💤 in The GitHub CLI Sep 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
The GitHub CLI
  
Done 💤
Development

Successfully merging this pull request may close these issues.

gh pr diff could use default pager
3 participants