Skip to content

Using default pager in gh pr diff - #1534

Merged
vilmibm merged 1 commit into
cli:trunkfrom
mmontes11:pr-diff-use-default-pager
Aug 19, 2020
Merged

vilmibm merged 1 commit into
cli:trunkfrom
mmontes11:pr-diff-use-default-pager

Conversation

@mmontes11

@mmontes11 mmontes11 commented Aug 15, 2020 •

Copy link
Copy Markdown
Contributor

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 force-pushed the pr-diff-use-default-pager branch from 29cf9ae to a75dde0 Compare August 15, 2020 12:51
@mmontes11
mmontes11 marked this pull request as ready for review August 15, 2020 13:11

@mislav mislav left a comment

Copy link
Copy Markdown
Contributor

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

Comment thread pkg/cmd/pr/diff/diff.go Resolved
Comment thread pkg/cmd/pr/diff/diff.go Outdated
}

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

Copy link
Copy Markdown
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?

@mmontes11 mmontes11 Aug 17, 2020 •

Copy link
Copy Markdown
Contributor Author

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

@mislav mislav left a comment

Copy link
Copy Markdown
Contributor

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!

Comment thread pkg/cmd/pr/diff/diff.go Resolved
@mmontes11
mmontes11 force-pushed the pr-diff-use-default-pager branch from 2ca3e24 to df66a8f Compare August 17, 2020 20:31

@mislav mislav left a comment •

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

vilmibm commented Aug 17, 2020

Copy link
Copy Markdown
Contributor

thank you!

@vilmibm
vilmibm merged commit 88b5a3b into cli:trunk Aug 19, 2020
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.

gh pr diff could use default pager

3 participants