Skip to content

Commit

Permalink
fix(git): show an error when there is no key in the agent
Browse files Browse the repository at this point in the history
Closes #8.
  • Loading branch information
tagoro9 committed Mar 17, 2017
1 parent 5de421e commit 26fc141
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
3 changes: 2 additions & 1 deletion src/error/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ export default {
branchAlreadyExists: 'It looks like you already have a branch for this issue.',
couldNotInitializeRepo: 'We have problems accessing the repo in \'${pathToRepo}\'. Make sure it exists.',
noChanges: 'You haven\'t made any changes to this branch',
noIssueInBranchName: 'We couldn\'t find the issue name on the branch. Maybe you should run `fotingo review -n`.'
noIssueInBranchName: 'We couldn\'t find the issue name on the branch. Maybe you should run `fotingo review -n`.',
noSshKey: 'It looks like you haven\'t added you ssh key. Remember to `ssh-add -k path_to_private_key` so we can communicate with the remote repository.'
},
github: {
cantConnect: 'We can\' connect to github right now. Try in a few moments',
Expand Down
29 changes: 17 additions & 12 deletions src/git/local/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@ import { createBranchName, getIssueIdFromBranch } from '../util';
import { debug, debugCurried, debugCurriedP, wrapInPromise } from '../../util';
import app from '../../../package.json';

const fetchOptions = {
callbacks: {
certificateCheck: R.always(1),
credentials: R.compose(
Git.Cred.sshKeyFromAgent,
debugCurried('git', 'Getting authentication from SSH agent'),
// TODO Detect ssh key not present
R.nthArg(1)
)
}
const fetchOptions = () => {
let credentialsCallCount = 0;
return {
callbacks: {
certificateCheck: R.always(1),
credentials: R.compose(
Git.Cred.sshKeyFromAgent,
debugCurried('git', 'Getting authentication from SSH agent'),
username => (credentialsCallCount++ > 0 ? undefined : username),
R.nthArg(1)
)
}
};
};

let repository = null;
Expand Down Expand Up @@ -59,7 +62,8 @@ export default {
const { remote, branch } = config.get(['git']);
debug('git', 'Fetching data from remote');
// We should fetch -> co master -> reset to origin/master -> create branch
return repository.fetch(remote, fetchOptions)
return repository.fetch(remote, fetchOptions())
.catch(throwControlledError(errors.git.noSshKey))
.then(debugCurriedP('git', 'Getting local repository status'))
.then(() => repository.getStatus())
.then(R.ifElse(
Expand Down Expand Up @@ -89,7 +93,8 @@ export default {
}),
getCurrentBranchName,
pushBranchToGithub: R.converge(
R.composeP(([remote, branch, { branchName, ref }]) => remote.push([ref], fetchOptions)
R.composeP(([remote, branch, { branchName, ref }]) => remote.push([ref], fetchOptions())
.catch(throwControlledError(errors.git.noSshKey))
.then(() => Git.Branch.setUpstream(branch, `${remote.name()}/${branchName}`)),
(...promises) => Promise.all(promises)),
[
Expand Down

0 comments on commit 26fc141

Please sign in to comment.