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

feat(git): add support for git url aliases #633

Merged
merged 1 commit into from Mar 28, 2020
Merged

feat(git): add support for git url aliases #633

merged 1 commit into from Mar 28, 2020

Conversation

SuperITMan
Copy link
Contributor

@SuperITMan SuperITMan commented Mar 27, 2020

Hello everyone,

I propose a small improvement for your great tool 😊

In my git config, I implemented some git url aliases including the following one:

[url "git@github.com:"]
        insteadOf = "gh:"

Which allows me to clone like this: git clone gh:SuperITMan/stark.git.

If I want to get the url of my remote with git remote -v, I obtain:

origin  git@github.com:SuperITMan/stark.git (fetch)
origin  git@github.com:SuperITMan/stark.git (push)

But in release-it, currently, when the tool tries to get the remote url, it uses the command git config --get remote.origin.url which gives gh:SuperITMan/stark.git instead of git@github.com:SuperITman/stark.git.

See the error I get when I try to do a release (the url is wrong and GITHUB_TOKEN variable is useless):

npm run release -- -VV

> stark-srcs@10.0.0 release /home/superitman/GIT/stark
> release-it "-VV"

$ git config --get remote.origin.url
gh:SuperITMan/stark.git
$ git fetch
Enter passphrase for key '/home/superitman/.ssh/<ssh_key_name>':

$ git describe --tags --abbrev=0
10.0.0
$ npm run generate:changelog-recent
> stark-srcs@10.0.0 generate:changelog-recent /home/superitman/GIT/stark
> conventional-changelog -p angular | tail -n +3
octokit users#getAuthenticated
ERROR Could not authenticate with GitHub using environment variable "GITHUB_TOKEN".
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! stark-srcs@10.0.0 release: `release-it "-VV"`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the stark-srcs@10.0.0 release script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/superitman/.npm/_logs/2020-03-27T10_03_41_182Z-debug.log

The command git remote get-url <remote_name> is apparently available since Git 2.7 according to https://stackoverflow.com/a/32991784

@webpro
Copy link
Collaborator

webpro commented Mar 27, 2020

Thanks, @SuperITMan! I definitely like to merge this, but release-it works from Git v2.0.0, so it would be good to have a fallback. Could you please add the old version of the command in a catch block? Thanks!

@SuperITMan
Copy link
Contributor Author

Hey @webpro
I wanted to test the project with my change on Git 2.0.0 but it is not available anymore on Debian / Ubuntu / Arch Linux. Nevertheless, I found the version 2.5.2 in Windows Portable version on GitHub: https://github.com/git-for-windows/git/releases/tag/v2.5.2.windows.1

I tested the current version of release-it (without my change) and a test is failing:

test.serial('should push to remote name (not "origin")', async t => {
  const bare = mkTmpDir();
  sh.exec(`git init --bare ${bare}`);
  sh.exec(`git clone ${bare} .`);
  gitAdd('line', 'file', 'Add file');
  sh.exec(`git remote add upstream ${sh.exec('git remote get-url origin')}`);
  // ...

with the following error:

1 test failed

  git » should push to remote name (not "origin")

  ..\..\..\AppData\Local\Temp\release-it-2944qojITNZqq70S\lib\shell.js:87

  Rejected promise returned by test. Reason:

  Error {
    message: `fatal: 'upstream' does not appear to be a git repository␊
    fatal: Could not read from remote repository.␊

    Please make sure you have the correct access rights␊
    and the repository exists.`,
  }

I think it does not really make sense to set the minimum version on 2.0.0 since probably no-one is using it. What would you think to upgrade the minimum version to 2.7.0 ? This version was released on January 5th, 2015 (more than 5 years ago).

Like this, all the tests would be ok and we could have support for url aliases in gitconfig 😊

Otherwise, I can add a try/catch but we should adapt also the other test should push to remote name (not "origin") to be sure everything is working well 👍

@webpro
Copy link
Collaborator

webpro commented Mar 28, 2020

Sorry for the hassle, don't worry about it. I installed Git v2.0.0 myself from source.

I truly have no idea how many people use old versions of Git (say, below v2.7..0). however, in this case it's fairly easy to maintain this support, so I'm going to merge your PR, and fix the support/tests.

@webpro webpro merged commit 2647871 into release-it:master Mar 28, 2020
@webpro
Copy link
Collaborator

webpro commented Mar 28, 2020

Thanks @SuperITMan! Your feature has just landed in v13.5.0.

@SuperITMan SuperITMan deleted the feature/add-support-git-url-aliases branch March 28, 2020 13:32
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.

None yet

2 participants