git-cliff icon indicating copy to clipboard operation
git-cliff copied to clipboard

feat: find upstream remote when using ssh

Open kemitix opened this issue 1 year ago • 2 comments

Description

When looking for the owner and repo of the remote for the current HEAD, we will now try to parse the SSH format of a remote if it fails to match an HTTPS format of a remote.

Motivation and Context

When the git-cliff repo is cloned for development using the SSH protocol, the test repo::test::git_upstream_remote fails.

The upstream_remote function was relying on url::Url::parse to extract the owner and repo from the url. But that only works when the repo is cloned using HTTPS, e.g. https://github.com/orhun/git-cliff.git. However, this would fail to parse when cloned using SSH, e.g. [email protected]:orhun/git-cliff.git.

Now, if the url::URL::parser fails, we now try to parse an SSH remote in the format git@hostname:owner/repo.git.

The error from upstream_remote also notes that a possible reason for it failing would be that the HEAD is detached.

How Has This Been Tested?

  • Fork the orhun/git-cliff repo as kemitix/git-cliff
  • Clone using SSH, with a remote of [email protected]:kemitix/git-cliff.git
  • Run cargo test - all tests pass, including repo::test::git_upstream_remote

Screenshots / Logs (if applicable)

n/a

Types of Changes

  • [ ] Bug fix (non-breaking change which fixes an issue)
  • [x] New feature (non-breaking change which adds functionality)
  • [ ] Breaking change (fix or feature that would cause existing functionality to change)
  • [ ] Documentation (no code change)
  • [ ] Refactor (refactoring production code)
  • [ ] Other

Checklist:

  • [x] My code follows the code style of this project.
  • [x] I have updated the documentation accordingly.
  • [x] I have formatted the code with rustfmt.
  • [x] I checked the lints with clippy.
  • [x] I have added tests to cover my changes.
  • [x] All new and existing tests passed.

kemitix avatar Oct 19 '24 15:10 kemitix

Thanks for opening this pull request! Please check out our contributing guidelines! ⛰️

welcome[bot] avatar Oct 19 '24 15:10 welcome[bot]

Codecov Report

Attention: Patch coverage is 74.07407% with 7 lines in your changes missing coverage. Please review.

Project coverage is 42.42%. Comparing base (82b10ac) to head (ea50194). Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
git-cliff-core/src/repo.rs 74.08% 7 Missing :warning:
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #926      +/-   ##
==========================================
+ Coverage   41.72%   42.42%   +0.71%     
==========================================
  Files          21       21              
  Lines        1678     1695      +17     
==========================================
+ Hits          700      719      +19     
+ Misses        978      976       -2     
Flag Coverage Δ
unit-tests 42.42% <74.08%> (+0.71%) :arrow_up:

Flags with carried forward coverage won't be shown. Click here to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov-commenter avatar Oct 19 '24 15:10 codecov-commenter

Thanks for the PR!

orhun avatar Oct 21 '24 20:10 orhun

Congrats on merging your first pull request! ⛰️

welcome[bot] avatar Oct 21 '24 20:10 welcome[bot]