diff --git a/asyncgit/src/sync/mod.rs b/asyncgit/src/sync/mod.rs index 8b3ea52c2b..52d57144c0 100644 --- a/asyncgit/src/sync/mod.rs +++ b/asyncgit/src/sync/mod.rs @@ -67,8 +67,8 @@ pub use state::{repo_state, RepoState}; pub use tags::{get_tags, CommitTags, Tags}; pub use tree::{tree_file_content, tree_files, TreeFile}; pub use utils::{ - get_head, get_head_tuple, is_bare_repo, is_repo, stage_add_all, - stage_add_file, stage_addremoved, Head, + get_head, get_head_tuple, is_bare_repo, is_repo, repo_dir, + stage_add_all, stage_add_file, stage_addremoved, Head, }; #[cfg(test)] diff --git a/asyncgit/src/sync/utils.rs b/asyncgit/src/sync/utils.rs index c98f983880..17a7507303 100644 --- a/asyncgit/src/sync/utils.rs +++ b/asyncgit/src/sync/utils.rs @@ -4,7 +4,11 @@ use super::CommitId; use crate::error::{Error, Result}; use git2::{IndexAddOption, Repository, RepositoryOpenFlags}; use scopetime::scope_time; -use std::{fs::File, io::Write, path::Path}; +use std::{ + fs::File, + io::Write, + path::{Path, PathBuf}, +}; /// #[derive(PartialEq, Debug, Clone)] @@ -56,6 +60,12 @@ pub(crate) fn work_dir(repo: &Repository) -> Result<&Path> { repo.workdir().ok_or(Error::NoWorkDir) } +/// path to .git folder +pub fn repo_dir(repo_path: &str) -> Result { + let repo = repo(repo_path)?; + Ok(repo.path().to_owned()) +} + /// pub fn repo_work_dir(repo_path: &str) -> Result { let repo = repo(repo_path)?; diff --git a/src/components/commit.rs b/src/components/commit.rs index 317f46825e..a6d1648e4f 100644 --- a/src/components/commit.rs +++ b/src/components/commit.rs @@ -4,7 +4,6 @@ use super::{ EventState, ExternalEditorComponent, }; use crate::{ - args::get_app_config_path, keys::SharedKeyConfig, queue::{InternalEvent, NeedsUpdate, Queue}, strings, @@ -24,7 +23,6 @@ use easy_cast::Cast; use std::{ fs::{read_to_string, File}, io::{Read, Write}, - path::PathBuf, }; use tui::{ backend::Backend, @@ -252,13 +250,10 @@ impl CommitComponent { } pub fn show_editor(&mut self) -> Result<()> { - const COMMIT_MSG_FILE_NAME: &str = "COMMITMSG_EDITOR"; - //TODO: use a tmpfile here - let mut config_path: PathBuf = get_app_config_path()?; - config_path.push(COMMIT_MSG_FILE_NAME); + let file_path = sync::repo_dir(CWD)?.join("COMMIT_EDITMSG"); { - let mut file = File::create(&config_path)?; + let mut file = File::create(&file_path)?; file.write_fmt(format_args!( "{}\n", self.input.get_text() @@ -269,14 +264,14 @@ impl CommitComponent { )?; } - ExternalEditorComponent::open_file_in_editor(&config_path)?; + ExternalEditorComponent::open_file_in_editor(&file_path)?; let mut message = String::new(); - let mut file = File::open(&config_path)?; + let mut file = File::open(&file_path)?; file.read_to_string(&mut message)?; drop(file); - std::fs::remove_file(&config_path)?; + std::fs::remove_file(&file_path)?; let message: String = message .lines()