Skip to content

Commit

Permalink
Allow git repo without remote when not pushing
Browse files Browse the repository at this point in the history
  • Loading branch information
webpro committed Jun 1, 2020
1 parent 86fc310 commit 39f3b9a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
8 changes: 2 additions & 6 deletions lib/plugin/GitBase.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const _ = require('lodash');
const { format, parseGitUrl } = require('../util');
const { GitRemoteUrlError, GitNetworkError } = require('../errors');
const { GitNetworkError } = require('../errors');
const Plugin = require('./Plugin');

const options = { write: false };
Expand All @@ -12,9 +11,6 @@ class GitBase extends Plugin {
}
async init() {
this.remoteUrl = await this.getRemoteUrl();
if (!this.remoteUrl) {
throw new GitRemoteUrlError();
}
await this.fetch();
const repo = parseGitUrl(this.remoteUrl);
const latestTagName = await this.getLatestTagName();
Expand Down Expand Up @@ -59,7 +55,7 @@ class GitBase extends Plugin {
}

isRemoteName(remoteUrlOrName) {
return !_.includes(remoteUrlOrName, '/');
return remoteUrlOrName && !remoteUrlOrName.includes('/');
}

async getRemoteUrl() {
Expand Down
4 changes: 4 additions & 0 deletions lib/plugin/git/Git.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const GitBase = require('../GitBase');
const {
GitRequiredBranchError,
GitCleanWorkingDirError,
GitRemoteUrlError,
GitUpstreamError,
GitNoCommitsError,
GitCommitError
Expand Down Expand Up @@ -34,6 +35,9 @@ class Git extends GitBase {
throw new GitCleanWorkingDirError();
}
await super.init();
if (this.options.push && !this.remoteUrl) {
throw new GitRemoteUrlError();
}
if (this.options.requireUpstream && !(await this.hasUpstreamBranch())) {
throw new GitUpstreamError();
}
Expand Down
3 changes: 2 additions & 1 deletion lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ const rejectAfter = ms =>
});

const parseGitUrl = remoteUrl => {
const normalizedUrl = remoteUrl.replace(/\\/g, '/');
if (!remoteUrl) return { host: null, owner: null, project: null, protocol: null, remote: null, repository: null };
const normalizedUrl = (remoteUrl || '').replace(/\\/g, '/');
const parsedUrl = gitUrlParse(normalizedUrl);
const { resource: host, name: project, protocol, href: remote } = parsedUrl;
const owner = protocol === 'file' ? _.last(parsedUrl.owner.split('/')) : parsedUrl.owner;
Expand Down

0 comments on commit 39f3b9a

Please sign in to comment.