From bac2de6ac666dafda234522bcfe8953b8c108933 Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Fri, 24 Mar 2023 08:21:56 -0700 Subject: [PATCH] cli: add hint about testing with `ssh -F /dev/null` on SSH errors --- src/commands/git.rs | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/src/commands/git.rs b/src/commands/git.rs index 0de0b40c1..0bbafcec8 100644 --- a/src/commands/git.rs +++ b/src/commands/git.rs @@ -9,7 +9,7 @@ use std::time::Instant; use clap::{ArgGroup, Subcommand}; use itertools::Itertools; use jujutsu_lib::backend::ObjectId; -use jujutsu_lib::git::{self, GitFetchError, GitRefUpdate}; +use jujutsu_lib::git::{self, GitFetchError, GitPushError, GitRefUpdate}; use jujutsu_lib::op_store::{BranchTarget, RefTarget}; use jujutsu_lib::refs::{classify_branch_push_action, BranchPushAction, BranchPushUpdate}; use jujutsu_lib::repo::Repo; @@ -20,8 +20,8 @@ use jujutsu_lib::workspace::Workspace; use maplit::hashset; use crate::cli_util::{ - print_failed_git_export, short_change_hash, short_commit_hash, user_error, CommandError, - CommandHelper, RevisionArg, WorkspaceCommandHelper, + print_failed_git_export, short_change_hash, short_commit_hash, user_error, + user_error_with_hint, CommandError, CommandHelper, RevisionArg, WorkspaceCommandHelper, }; use crate::commands::make_branch_term; use crate::progress::Progress; @@ -155,6 +155,18 @@ fn get_git_repo(store: &Store) -> Result { } } +fn map_git_error(err: git2::Error) -> CommandError { + if err.class() == git2::ErrorClass::Ssh { + user_error_with_hint( + err.to_string(), + "Jujutsu uses libssh2, which doesn't respect ~/.ssh/config. Does `ssh -F /dev/null` \ + to the host work?", + ) + } else { + user_error(err.to_string()) + } +} + fn cmd_git_remote_add( ui: &mut Ui, command: &CommandHelper, @@ -307,7 +319,10 @@ fn cmd_git_fetch( &command.settings().git_settings(), ) }) - .map_err(|err| user_error(err.to_string()))?; + .map_err(|err| match err { + GitFetchError::InternalGitError(err) => map_git_error(err), + _ => user_error(err.to_string()), + })?; } tx.finish(ui)?; Ok(()) @@ -439,7 +454,7 @@ fn do_git_clone( GitFetchError::NoSuchRemote(_) => { panic!("shouldn't happen as we just created the git remote") } - GitFetchError::InternalGitError(err) => user_error(format!("Fetch failed: {err}")), + GitFetchError::InternalGitError(err) => map_git_error(err), GitFetchError::InvalidGlob => { unreachable!("we didn't provide any globs") } @@ -860,7 +875,10 @@ fn cmd_git_push( with_remote_callbacks(ui, |cb| { git::push_updates(&git_repo, &remote, &ref_updates, cb) }) - .map_err(|err| user_error(err.to_string()))?; + .map_err(|err| match err { + GitPushError::InternalGitError(err) => map_git_error(err), + _ => user_error(err.to_string()), + })?; git::import_refs(tx.mut_repo(), &git_repo, &command.settings().git_settings())?; tx.finish(ui)?; Ok(())