change temporary commit msg file path

we now use `.git/COMMIT_EDITMSG` for vim to recognise
This commit is contained in:
Stephan Dilly 2021-05-24 10:29:50 +02:00
parent fdcd393ce7
commit 7177bb223b
3 changed files with 18 additions and 13 deletions

View file

@ -67,8 +67,8 @@ pub use state::{repo_state, RepoState};
pub use tags::{get_tags, CommitTags, Tags}; pub use tags::{get_tags, CommitTags, Tags};
pub use tree::{tree_file_content, tree_files, TreeFile}; pub use tree::{tree_file_content, tree_files, TreeFile};
pub use utils::{ pub use utils::{
get_head, get_head_tuple, is_bare_repo, is_repo, stage_add_all, get_head, get_head_tuple, is_bare_repo, is_repo, repo_dir,
stage_add_file, stage_addremoved, Head, stage_add_all, stage_add_file, stage_addremoved, Head,
}; };
#[cfg(test)] #[cfg(test)]

View file

@ -4,7 +4,11 @@ use super::CommitId;
use crate::error::{Error, Result}; use crate::error::{Error, Result};
use git2::{IndexAddOption, Repository, RepositoryOpenFlags}; use git2::{IndexAddOption, Repository, RepositoryOpenFlags};
use scopetime::scope_time; 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)] #[derive(PartialEq, Debug, Clone)]
@ -56,6 +60,12 @@ pub(crate) fn work_dir(repo: &Repository) -> Result<&Path> {
repo.workdir().ok_or(Error::NoWorkDir) repo.workdir().ok_or(Error::NoWorkDir)
} }
/// path to .git folder
pub fn repo_dir(repo_path: &str) -> Result<PathBuf> {
let repo = repo(repo_path)?;
Ok(repo.path().to_owned())
}
/// ///
pub fn repo_work_dir(repo_path: &str) -> Result<String> { pub fn repo_work_dir(repo_path: &str) -> Result<String> {
let repo = repo(repo_path)?; let repo = repo(repo_path)?;

View file

@ -4,7 +4,6 @@ use super::{
EventState, ExternalEditorComponent, EventState, ExternalEditorComponent,
}; };
use crate::{ use crate::{
args::get_app_config_path,
keys::SharedKeyConfig, keys::SharedKeyConfig,
queue::{InternalEvent, NeedsUpdate, Queue}, queue::{InternalEvent, NeedsUpdate, Queue},
strings, strings,
@ -24,7 +23,6 @@ use easy_cast::Cast;
use std::{ use std::{
fs::{read_to_string, File}, fs::{read_to_string, File},
io::{Read, Write}, io::{Read, Write},
path::PathBuf,
}; };
use tui::{ use tui::{
backend::Backend, backend::Backend,
@ -252,13 +250,10 @@ impl CommitComponent {
} }
pub fn show_editor(&mut self) -> Result<()> { pub fn show_editor(&mut self) -> Result<()> {
const COMMIT_MSG_FILE_NAME: &str = "COMMITMSG_EDITOR"; let file_path = sync::repo_dir(CWD)?.join("COMMIT_EDITMSG");
//TODO: use a tmpfile here
let mut config_path: PathBuf = get_app_config_path()?;
config_path.push(COMMIT_MSG_FILE_NAME);
{ {
let mut file = File::create(&config_path)?; let mut file = File::create(&file_path)?;
file.write_fmt(format_args!( file.write_fmt(format_args!(
"{}\n", "{}\n",
self.input.get_text() 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 message = String::new();
let mut file = File::open(&config_path)?; let mut file = File::open(&file_path)?;
file.read_to_string(&mut message)?; file.read_to_string(&mut message)?;
drop(file); drop(file);
std::fs::remove_file(&config_path)?; std::fs::remove_file(&file_path)?;
let message: String = message let message: String = message
.lines() .lines()