Skip to content
Open
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
28 changes: 20 additions & 8 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,25 @@ impl Environment {
}
}

/// Resolves `--file` to a path relative to the repository workdir (as used by the file tree).
fn resolve_select_file(file: PathBuf, repo: &RepoPath) -> Result<Option<PathBuf>> {
let workdir = PathBuf::from(repo_work_dir(repo)?);
let workdir_canon = workdir.canonicalize()?;

let candidates = [
file.canonicalize().ok(),
workdir.join(&file).canonicalize().ok(),
];

for abs in candidates.into_iter().flatten() {
if let Ok(rel) = abs.strip_prefix(&workdir_canon) {
return Ok(Some(Path::new(".").join(rel)));
}
}

Ok(None)
}

// public interface
impl App {
///
Expand Down Expand Up @@ -178,14 +197,7 @@ impl App {

let mut select_file: Option<PathBuf> = None;
let tab = if let Some(file) = cliargs.select_file {
// convert to relative git path
if let Ok(abs) = file.canonicalize() {
if let Ok(path) = abs.strip_prefix(
env.repo.borrow().gitpath().canonicalize()?,
) {
select_file = Some(Path::new(".").join(path));
}
}
select_file = resolve_select_file(file, &env.repo.borrow())?;
2
} else {
env.options.borrow().current_tab()
Expand Down