Skip to content

Commit 7177bb2

Browse files
author
Stephan Dilly
committed
change temporary commit msg file path
we now use `.git/COMMIT_EDITMSG` for vim to recognise
1 parent fdcd393 commit 7177bb2

File tree

3 files changed

+18
-13
lines changed

3 files changed

+18
-13
lines changed

asyncgit/src/sync/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ pub use state::{repo_state, RepoState};
6767
pub use tags::{get_tags, CommitTags, Tags};
6868
pub use tree::{tree_file_content, tree_files, TreeFile};
6969
pub use utils::{
70-
get_head, get_head_tuple, is_bare_repo, is_repo, stage_add_all,
71-
stage_add_file, stage_addremoved, Head,
70+
get_head, get_head_tuple, is_bare_repo, is_repo, repo_dir,
71+
stage_add_all, stage_add_file, stage_addremoved, Head,
7272
};
7373

7474
#[cfg(test)]

asyncgit/src/sync/utils.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ use super::CommitId;
44
use crate::error::{Error, Result};
55
use git2::{IndexAddOption, Repository, RepositoryOpenFlags};
66
use scopetime::scope_time;
7-
use std::{fs::File, io::Write, path::Path};
7+
use std::{
8+
fs::File,
9+
io::Write,
10+
path::{Path, PathBuf},
11+
};
812

913
///
1014
#[derive(PartialEq, Debug, Clone)]
@@ -56,6 +60,12 @@ pub(crate) fn work_dir(repo: &Repository) -> Result<&Path> {
5660
repo.workdir().ok_or(Error::NoWorkDir)
5761
}
5862

63+
/// path to .git folder
64+
pub fn repo_dir(repo_path: &str) -> Result<PathBuf> {
65+
let repo = repo(repo_path)?;
66+
Ok(repo.path().to_owned())
67+
}
68+
5969
///
6070
pub fn repo_work_dir(repo_path: &str) -> Result<String> {
6171
let repo = repo(repo_path)?;

src/components/commit.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use super::{
44
EventState, ExternalEditorComponent,
55
};
66
use crate::{
7-
args::get_app_config_path,
87
keys::SharedKeyConfig,
98
queue::{InternalEvent, NeedsUpdate, Queue},
109
strings,
@@ -24,7 +23,6 @@ use easy_cast::Cast;
2423
use std::{
2524
fs::{read_to_string, File},
2625
io::{Read, Write},
27-
path::PathBuf,
2826
};
2927
use tui::{
3028
backend::Backend,
@@ -252,13 +250,10 @@ impl CommitComponent {
252250
}
253251

254252
pub fn show_editor(&mut self) -> Result<()> {
255-
const COMMIT_MSG_FILE_NAME: &str = "COMMITMSG_EDITOR";
256-
//TODO: use a tmpfile here
257-
let mut config_path: PathBuf = get_app_config_path()?;
258-
config_path.push(COMMIT_MSG_FILE_NAME);
253+
let file_path = sync::repo_dir(CWD)?.join("COMMIT_EDITMSG");
259254

260255
{
261-
let mut file = File::create(&config_path)?;
256+
let mut file = File::create(&file_path)?;
262257
file.write_fmt(format_args!(
263258
"{}\n",
264259
self.input.get_text()
@@ -269,14 +264,14 @@ impl CommitComponent {
269264
)?;
270265
}
271266

272-
ExternalEditorComponent::open_file_in_editor(&config_path)?;
267+
ExternalEditorComponent::open_file_in_editor(&file_path)?;
273268

274269
let mut message = String::new();
275270

276-
let mut file = File::open(&config_path)?;
271+
let mut file = File::open(&file_path)?;
277272
file.read_to_string(&mut message)?;
278273
drop(file);
279-
std::fs::remove_file(&config_path)?;
274+
std::fs::remove_file(&file_path)?;
280275

281276
let message: String = message
282277
.lines()

0 commit comments

Comments
 (0)