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

fix(git): show an error when there is no key in the agent #30

Merged
merged 1 commit into from
Mar 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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