From 8c80be2f852b423c7b7dfacdc74a78d4ccda4c35 Mon Sep 17 00:00:00 2001 From: hotoo Date: Thu, 25 Apr 2019 10:29:33 +0800 Subject: [PATCH 1/3] feat: support remote argument (-r, --remote) --- bin/gitopen | 5 ++++- lib/gitremote.js | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/bin/gitopen b/bin/gitopen index 2adea79..04c7664 100755 --- a/bin/gitopen +++ b/bin/gitopen @@ -38,7 +38,10 @@ commander(process.argv, { // 5. git/hg/svn remote url. var uri; try { - uri = gitremote.getRemoteUrl({cwd: process.cwd()}); + uri = gitremote.getRemoteUrl({ + cwd: process.cwd(), + remote: command.remote, + }); } catch (ex) { if (command.category === 'snippets/new') { uri = 'https://github.com/hotoo/gitopen'; diff --git a/lib/gitremote.js b/lib/gitremote.js index 1424424..f25588c 100644 --- a/lib/gitremote.js +++ b/lib/gitremote.js @@ -9,7 +9,7 @@ exports.getRemoteUrl = function getRemoteUrl(options) { } var cwd = options.cwd || process.cwd(); var uri = child_process.execSync( - 'git config remote.' + (options.origin || 'origin') + '.url', + 'git config remote.' + (options.remote || 'origin') + '.url', {cwd: cwd} ).toString().trim(); From 425da9cdbd7c1e9ccabc4f7c78bb7d7fdcae69bf Mon Sep 17 00:00:00 2001 From: hotoo Date: Thu, 25 Apr 2019 10:47:31 +0800 Subject: [PATCH 2/3] test: gitopen --remote --- test/gitopen.test.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/test/gitopen.test.js b/test/gitopen.test.js index 572eabf..1447c7b 100644 --- a/test/gitopen.test.js +++ b/test/gitopen.test.js @@ -381,8 +381,12 @@ describe('gitremote()', function() { resolve(gitremote.getRemoteUrl({cwd: '.'})).should.be.eql('github.com/hotoo/gitopen'); }); - it('gitremote.getRemoteUrl({remote})', function() { + it('gitremote.getRemoteUrl({remote})', function(done) { resolve(gitremote.getRemoteUrl({remote: 'origin'})).should.be.eql('github.com/hotoo/gitopen'); + child_process.exec('git remote add gitlab git@gitlab.com:hotoo/gitopen.git', {cwd: '.'}, function(/* err, stdout */) { + resolve(gitremote.getRemoteUrl({remote: 'gitlab'})).should.be.eql('gitlab.com/hotoo/gitopen'); + done(); + }); }); }); @@ -506,6 +510,14 @@ describe('$ gitopen', function() { }); }); + it('$ gitopen --remote gitlab', function(done) { + child_process.exec('./bin/gitopen --verbose --remote gitlab', function(err, stdout) { + should(err).not.be.ok(); + stdout.should.be.containEql('URL: https://gitlab.com/hotoo/gitopen\n'); + done(); + }); + }); + var git_command_case_in_subdir = [ ['../README.md :master', '/hotoo/gitopen/blob/master/README.md'], ['../README.md -b master', '/hotoo/gitopen/blob/master/README.md'], From 49cf1fc888029c7d7c4c18e2de366a84df7981aa Mon Sep 17 00:00:00 2001 From: hotoo Date: Thu, 25 Apr 2019 11:02:37 +0800 Subject: [PATCH 3/3] =?UTF-8?q?test:=20=E4=BF=AE=E6=94=B9=E4=BA=86=20githu?= =?UTF-8?q?b=20=E7=9A=84=20PR=20=E7=9B=B8=E5=85=B3=20scheme=20=E9=85=8D?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/gitopen.test.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/gitopen.test.js b/test/gitopen.test.js index 1447c7b..a77e4c3 100644 --- a/test/gitopen.test.js +++ b/test/gitopen.test.js @@ -464,11 +464,11 @@ describe('$ gitopen', function() { ['pull', '/hotoo/gitopen/compare/' + cwb + '?expand=1'], ['pr compare-branch', '/hotoo/gitopen/compare/compare-branch?expand=1'], ['pull compare-branch', '/hotoo/gitopen/compare/compare-branch?expand=1'], - ['pr base-branch:compare-branch', '/hotoo/gitopen/compare/base-branch...compare-branch'], - ['pr base/branch:compare/branch', '/hotoo/gitopen/compare/base/branch...compare/branch'], - ['pr base-branch...compare-branch', '/hotoo/gitopen/compare/base-branch...compare-branch'], - ['pr base/branch...compare/branch', '/hotoo/gitopen/compare/base/branch...compare/branch'], - ['pr base/branch+name...compare/branch#name', '/hotoo/gitopen/compare/base/branch%2Bname...compare/branch%23name'], + ['pr base-branch:compare-branch', '/hotoo/gitopen/compare/base-branch...compare-branch?expand=1'], + ['pr base/branch:compare/branch', '/hotoo/gitopen/compare/base/branch...compare/branch?expand=1'], + ['pr base-branch...compare-branch', '/hotoo/gitopen/compare/base-branch...compare-branch?expand=1'], + ['pr base/branch...compare/branch', '/hotoo/gitopen/compare/base/branch...compare/branch?expand=1'], + ['pr base/branch+name...compare/branch#name', '/hotoo/gitopen/compare/base/branch%2Bname...compare/branch%23name?expand=1'], ['pulls', '/hotoo/gitopen/pulls'], ['prs', '/hotoo/gitopen/pulls'], ['mrs', '/hotoo/gitopen/pulls'],