Skip to content

Commit

Permalink
fix(git): improve error message when push fails
Browse files Browse the repository at this point in the history
Fixes #117
  • Loading branch information
tagoro9 committed Sep 22, 2020
1 parent 578b264 commit dd377cb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/git/Git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,11 @@ export class Git {
if (remoteExists) {
this.messenger.emit('Pushing branch', Emoji.ARROW_UP);
this.messenger.inThread(true);
await this.git.push(this.config.remote);
try {
await this.git.push(this.config.remote);
} catch (error) {
this.mapAndThrowError(error);
}
this.messenger.inThread(false);
return;
}
Expand Down Expand Up @@ -344,6 +348,11 @@ export class Git {
if (error.message.match(/not a git repository/)) {
throw new GitErrorImpl(error.message, GitErrorType.NOT_A_GIT_REPO);
}
if (
error.message.match(/Updates were rejected because the tip of your current branch is behind/)
) {
throw new GitErrorImpl(error.message, GitErrorType.FORCE_PUSH);
}
throw error;
}

Expand Down
1 change: 1 addition & 0 deletions src/git/GitError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export enum GitErrorType {
BRANCH_ALREADY_EXISTS,
NOT_A_GIT_REPO,
NO_REMOTE,
FORCE_PUSH,
}

export interface GitError {
Expand Down
4 changes: 4 additions & 0 deletions src/ui/errorCodeToMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@ import { GitErrorType } from 'src/git/GitError';
export const ERROR_CODE_TO_MESSAGE: { [k: number]: string } = {
[GitErrorType.BRANCH_ALREADY_EXISTS]: 'It looks like there is a branch already for this issue',
[GitErrorType.NOT_A_GIT_REPO]: 'It looks like you run fotingo outside of a git repository',
[GitErrorType.FORCE_PUSH]:
'It looks like your branch is behind the remote. Fotingo does not support force pushing',
[GitErrorType.BRANCH_ALREADY_EXISTS]:
'It looks like your repository does not have a remote configured',
};

0 comments on commit dd377cb

Please sign in to comment.