Skip to content

change temporary commit msg file path #733

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 24, 2021
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions asyncgit/src/sync/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
12 changes: 11 additions & 1 deletion asyncgit/src/sync/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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<PathBuf> {
let repo = repo(repo_path)?;
Ok(repo.path().to_owned())
}

///
pub fn repo_work_dir(repo_path: &str) -> Result<String> {
let repo = repo(repo_path)?;
Expand Down
15 changes: 5 additions & 10 deletions src/components/commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use super::{
EventState, ExternalEditorComponent,
};
use crate::{
args::get_app_config_path,
keys::SharedKeyConfig,
queue::{InternalEvent, NeedsUpdate, Queue},
strings,
Expand All @@ -24,7 +23,6 @@ use easy_cast::Cast;
use std::{
fs::{read_to_string, File},
io::{Read, Write},
path::PathBuf,
};
use tui::{
backend::Backend,
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand Down