mirror of
https://github.com/extrawurst/gitui.git
synced 2024-12-27 11:03:03 +03:00
do shell expansion for commit.template
more error logging around commit-template loading
This commit is contained in:
parent
403c5aabd9
commit
495d4d5da7
@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
* fix commit dialog char count for multibyte characters ([#1726](https://github.com/extrawurst/gitui/issues/1726))
|
||||
* fix wrong hit highlighting in fuzzy find popup [[@UUGTech](https://github.com/UUGTech)] ([#1731](https://github.com/extrawurst/gitui/pull/1731))
|
||||
* fix symlink support for configuration files [[@TheBlackSheep3](https://github.com/TheBlackSheep3)] ([#1751](https://github.com/extrawurst/gitui/issues/1751))
|
||||
* expand `~` in `commit.template` ([#1745](https://github.com/extrawurst/gitui/pull/1745))
|
||||
|
||||
## [0.23.0] - 2022-06-19
|
||||
|
||||
|
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -755,6 +755,7 @@ dependencies = [
|
||||
"scopeguard",
|
||||
"scopetime",
|
||||
"serde",
|
||||
"shellexpand",
|
||||
"simplelog",
|
||||
"struct-patch",
|
||||
"syntect",
|
||||
|
@ -47,6 +47,7 @@ ron = "0.8"
|
||||
scopeguard = "1.2"
|
||||
scopetime = { path = "./scopetime", version = "0.1" }
|
||||
serde = "1.0"
|
||||
shellexpand = "3.1"
|
||||
simplelog = { version = "0.12", default-features = false }
|
||||
struct-patch = "0.2"
|
||||
syntect = { version = "5.0", default-features = false, features = ["parsing", "default-syntaxes", "default-themes", "html"] }
|
||||
|
@ -30,6 +30,8 @@ use ratatui::{
|
||||
use std::{
|
||||
fs::{read_to_string, File},
|
||||
io::{Read, Write},
|
||||
path::PathBuf,
|
||||
str::FromStr,
|
||||
};
|
||||
|
||||
enum CommitResult {
|
||||
@ -364,61 +366,80 @@ impl CommitComponent {
|
||||
|
||||
let repo_state = sync::repo_state(&self.repo.borrow())?;
|
||||
|
||||
self.mode =
|
||||
if repo_state != RepoState::Clean && reword.is_some() {
|
||||
bail!("cannot reword while repo is not in a clean state");
|
||||
} else if let Some(reword_id) = reword {
|
||||
self.input.set_text(
|
||||
sync::get_commit_details(
|
||||
self.mode = if repo_state != RepoState::Clean
|
||||
&& reword.is_some()
|
||||
{
|
||||
bail!("cannot reword while repo is not in a clean state");
|
||||
} else if let Some(reword_id) = reword {
|
||||
self.input.set_text(
|
||||
sync::get_commit_details(
|
||||
&self.repo.borrow(),
|
||||
reword_id,
|
||||
)?
|
||||
.message
|
||||
.unwrap_or_default()
|
||||
.combine(),
|
||||
);
|
||||
self.input.set_title(strings::commit_reword_title());
|
||||
Mode::Reword(reword_id)
|
||||
} else {
|
||||
match repo_state {
|
||||
RepoState::Merge => {
|
||||
let ids =
|
||||
sync::mergehead_ids(&self.repo.borrow())?;
|
||||
self.input
|
||||
.set_title(strings::commit_title_merge());
|
||||
self.input.set_text(sync::merge_msg(
|
||||
&self.repo.borrow(),
|
||||
reword_id,
|
||||
)?
|
||||
.message
|
||||
.unwrap_or_default()
|
||||
.combine(),
|
||||
);
|
||||
self.input.set_title(strings::commit_reword_title());
|
||||
Mode::Reword(reword_id)
|
||||
} else {
|
||||
match repo_state {
|
||||
RepoState::Merge => {
|
||||
let ids =
|
||||
sync::mergehead_ids(&self.repo.borrow())?;
|
||||
self.input
|
||||
.set_title(strings::commit_title_merge());
|
||||
self.input.set_text(sync::merge_msg(
|
||||
&self.repo.borrow(),
|
||||
)?);
|
||||
Mode::Merge(ids)
|
||||
}
|
||||
RepoState::Revert => {
|
||||
self.input
|
||||
.set_title(strings::commit_title_revert());
|
||||
self.input.set_text(sync::merge_msg(
|
||||
&self.repo.borrow(),
|
||||
)?);
|
||||
Mode::Revert
|
||||
}
|
||||
|
||||
_ => {
|
||||
self.commit_template = get_config_string(
|
||||
&self.repo.borrow(),
|
||||
"commit.template",
|
||||
)
|
||||
.ok()
|
||||
.flatten()
|
||||
.and_then(|path| read_to_string(path).ok());
|
||||
|
||||
if self.is_empty() {
|
||||
if let Some(s) = &self.commit_template {
|
||||
self.input.set_text(s.clone());
|
||||
}
|
||||
}
|
||||
self.input.set_title(strings::commit_title());
|
||||
Mode::Normal
|
||||
}
|
||||
)?);
|
||||
Mode::Merge(ids)
|
||||
}
|
||||
};
|
||||
RepoState::Revert => {
|
||||
self.input
|
||||
.set_title(strings::commit_title_revert());
|
||||
self.input.set_text(sync::merge_msg(
|
||||
&self.repo.borrow(),
|
||||
)?);
|
||||
Mode::Revert
|
||||
}
|
||||
|
||||
_ => {
|
||||
self.commit_template = get_config_string(
|
||||
&self.repo.borrow(),
|
||||
"commit.template",
|
||||
)
|
||||
.map_err(|e| {
|
||||
log::error!("load git-config failed: {}", e);
|
||||
e
|
||||
})
|
||||
.ok()
|
||||
.flatten()
|
||||
.and_then(|path| {
|
||||
shellexpand::full(path.as_str())
|
||||
.ok()
|
||||
.and_then(|path| {
|
||||
PathBuf::from_str(path.as_ref()).ok()
|
||||
})
|
||||
})
|
||||
.and_then(|path| {
|
||||
read_to_string(&path)
|
||||
.map_err(|e| {
|
||||
log::error!("read commit.template failed: {e} (path: '{:?}')",path);
|
||||
e
|
||||
})
|
||||
.ok()
|
||||
});
|
||||
|
||||
if self.is_empty() {
|
||||
if let Some(s) = &self.commit_template {
|
||||
self.input.set_text(s.clone());
|
||||
}
|
||||
}
|
||||
self.input.set_title(strings::commit_title());
|
||||
Mode::Normal
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
self.commit_msg_history_idx = 0;
|
||||
self.input.show()?;
|
||||
|
Loading…
Reference in New Issue
Block a user