Skip to content
Open
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
54 changes: 48 additions & 6 deletions asyncgit/src/sync/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,51 @@ pub struct Head {
pub id: CommitId,
}

fn format_repo_open_error(err: &str, path: &Path) -> String {
let err_lower = err.to_ascii_lowercase();

if err_lower.contains("bare") {
return format!(
"repository at '{}' appears to be bare; pass an explicit worktree with -w",
path.display()
);
}

if err_lower.contains("not found")
|| err_lower.contains("could not find")
|| err_lower.contains("no such file")
|| err_lower.contains("failed to discover")
{
return format!(
"could not open git repository at '{}' ({err})\n\
hint: verify the path exists and is readable (sandboxing may block access)",
path.display()
);
}

format!(
"could not open git repository at '{}': {err}",
path.display()
)
}

///
pub fn repo_open_error(repo_path: &RepoPath) -> Option<String> {
let path = repo_path.gitpath();

if let Err(e) = Repository::open_ext(
repo_path.gitpath(),
path,
RepositoryOpenFlags::FROM_ENV,
Vec::<&Path>::new(),
) {
return Some(e.to_string());
return Some(format_repo_open_error(&e.to_string(), path));
}

gix::ThreadSafeRepository::discover_with_environment_overrides(
repo_path.gitpath(),
)
.map_or_else(|e| Some(e.to_string()), |_| None)
gix::ThreadSafeRepository::discover_with_environment_overrides(path)
.map_or_else(
|e| Some(format_repo_open_error(&e.to_string(), path)),
|_| None,
)
}

///
Expand Down Expand Up @@ -482,6 +513,17 @@ mod tests {
Ok(())
}

#[test]
fn format_repo_open_error_not_found() {
let msg = format_repo_open_error(
"repository not found",
Path::new("/i4/repo"),
);
assert!(msg.contains("could not open git repository"));
assert!(msg.contains("sandboxing"));
assert!(!msg.to_ascii_lowercase().contains("non-bare"));
}

#[test]
fn test_head_empty() -> Result<()> {
let (_td, repo) = repo_init_empty()?;
Expand Down
34 changes: 31 additions & 3 deletions src/components/textinput.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,15 +259,31 @@ impl TextInputComponent {
}
}

fn is_text_char_input(ctrl: bool, alt: bool) -> bool {
if !ctrl && !alt {
return true;
}

#[cfg(windows)]
{
// AltGr is commonly reported as Ctrl+Alt on Windows (e.g. German `{` `}`)
if ctrl && alt {
return true;
}
}

false
}

#[allow(clippy::too_many_lines, clippy::unnested_or_patterns)]
fn process_inputs(ta: &mut TextArea<'_>, input: &Input) -> bool {
match input {
Input {
key: Key::Char(c),
ctrl: false,
alt: false,
ctrl,
alt,
..
} => {
} if Self::is_text_char_input(*ctrl, *alt) => {
ta.insert_char(*c);
true
}
Expand Down Expand Up @@ -887,4 +903,16 @@ mod tests {
assert_eq!(ta.cursor(), save_cursor);
}
}

#[test]
fn test_is_text_char_input_without_modifiers() {
assert!(TextInputComponent::is_text_char_input(false, false));
assert!(!TextInputComponent::is_text_char_input(true, false));
}

#[test]
#[cfg(windows)]
fn test_is_text_char_input_altgr() {
assert!(TextInputComponent::is_text_char_input(true, true));
}
}