mirror of
https://github.com/denisidoro/navi.git
synced 2026-01-23 02:14:19 +00:00
Added a start of a functional copy of the .git folder
Signed-off-by: alexis-opolka <53085471+alexis-opolka@users.noreply.github.com>
This commit is contained in:
parent
138b7e0b00
commit
50cd89cbbe
2 changed files with 47 additions and 0 deletions
|
|
@ -5,6 +5,8 @@ use crate::finder::FinderChoice;
|
|||
use crate::prelude::*;
|
||||
use std::fs;
|
||||
use std::path;
|
||||
use std::path::{MAIN_SEPARATOR, MAIN_SEPARATOR_STR};
|
||||
|
||||
|
||||
fn ask_if_should_import_all(finder: &FinderChoice) -> Result<bool> {
|
||||
let opts = FinderOpts {
|
||||
|
|
@ -44,6 +46,7 @@ pub fn main(uri: String) -> Result<()> {
|
|||
.with_context(|| format!("Failed to clone `{actual_uri}`"))?;
|
||||
|
||||
let all_files = filesystem::all_cheat_files(&tmp_pathbuf).join("\n");
|
||||
let git_files = filesystem::all_git_files(&tmp_pathbuf).join("\n");
|
||||
|
||||
let opts = FinderOpts {
|
||||
suggestion_type: SuggestionType::MultipleSelections,
|
||||
|
|
@ -92,6 +95,30 @@ pub fn main(uri: String) -> Result<()> {
|
|||
.with_context(|| format!("Failed to copy `{}` to `{}`", &from.to_string(), &to.to_string()))?;
|
||||
}
|
||||
|
||||
// We are copying the .git folder along with the cheat files
|
||||
// For more details, see: (https://github.com/denisidoro/navi/issues/733)
|
||||
for file in git_files.split('\n') {
|
||||
let filename = format!("{}{}", &tmp_path_str, &file);
|
||||
let from = {
|
||||
let mut p = tmp_pathbuf.clone();
|
||||
p.push(&filename);
|
||||
p
|
||||
};
|
||||
let to = {
|
||||
let mut p = to_folder.clone();
|
||||
p.push(&file);
|
||||
p
|
||||
};
|
||||
|
||||
let path_str = &PathBuf::clone(&to).to_string();
|
||||
let local_collection = &path_str.split(MAIN_SEPARATOR).collect::<Vec<&str>>();
|
||||
let local_to_folder = format!("{}{}", &to_folder.to_string(), local_collection[0..&local_collection.len()-1].join(MAIN_SEPARATOR_STR));
|
||||
|
||||
fs::create_dir_all(&local_to_folder).unwrap_or(());
|
||||
fs::copy(&from, format!("{}{}", &to_folder.clone().to_str().unwrap(), &to.clone().to_str().unwrap()))
|
||||
.with_context(|| format!("Failed to copy `{}` to `{}`", &from.to_string(), &to.to_string()))?;
|
||||
}
|
||||
|
||||
filesystem::remove_dir(&tmp_pathbuf)?;
|
||||
|
||||
eprintln!(
|
||||
|
|
|
|||
|
|
@ -29,6 +29,26 @@ pub fn all_cheat_files(path: &Path) -> Vec<String> {
|
|||
.collect::<Vec<String>>()
|
||||
}
|
||||
|
||||
pub fn all_git_files(path: &Path) -> Vec<String> {
|
||||
let mut path_str = path.to_str().unwrap().to_owned();
|
||||
if path_str.ends_with("/") {
|
||||
// We're removing the trailing '/' at the end, if it exists
|
||||
path_str.push_str("/");
|
||||
}
|
||||
|
||||
WalkDir::new(path)
|
||||
.follow_links(true)
|
||||
.into_iter()
|
||||
.filter_map(|e| e.ok())
|
||||
.map(|e| {
|
||||
return if e.path().is_file() {
|
||||
e.path().to_str().unwrap().replace(path_str.as_str(), "").to_string()
|
||||
} else { "".to_string() };
|
||||
})
|
||||
.filter(|e| e.contains("/.git/"))
|
||||
.collect::<Vec<String>>()
|
||||
}
|
||||
|
||||
fn paths_from_path_param(env_var: &str) -> impl Iterator<Item = &str> {
|
||||
env_var.split(JOIN_SEPARATOR).filter(|folder| folder != &"")
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue