mirror of
https://github.com/gitui-org/gitui
synced 2026-05-23 08:58:21 +00:00
Merge 89fe3af99a into 8619c07f3f
This commit is contained in:
commit
2d3c66320f
2 changed files with 79 additions and 9 deletions
|
|
@ -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,
|
||||
)
|
||||
}
|
||||
|
||||
///
|
||||
|
|
@ -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()?;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue