mirror of
https://github.com/gitui-org/gitui
synced 2026-05-23 08:58:21 +00:00
show merge head ids in merge state (#697)
This commit is contained in:
parent
bc7cef747c
commit
f30ec49886
6 changed files with 68 additions and 11 deletions
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
|
|
@ -38,7 +38,7 @@ jobs:
|
|||
|
||||
- name: MacOS Workaround
|
||||
if: matrix.os == 'macos-latest'
|
||||
run: cargo clean --locked -p serde_derive -p thiserror
|
||||
run: cargo clean -p serde_derive -p thiserror
|
||||
|
||||
- name: Install Rust
|
||||
uses: actions-rs/toolchain@v1
|
||||
|
|
|
|||
12
Cargo.lock
generated
12
Cargo.lock
generated
|
|
@ -312,9 +312,9 @@ checksum = "0e4075386626662786ddb0ec9081e7c7eeb1ba31951f447ca780ef9f5d568189"
|
|||
|
||||
[[package]]
|
||||
name = "git2"
|
||||
version = "0.13.18"
|
||||
version = "0.13.19"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b483c6c2145421099df1b4efd50e0f6205479a072199460eff852fa15e5603c7"
|
||||
checksum = "17929de7239dea9f68aa14f94b2ab4974e7b24c1314275ffcc12a7758172fa18"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"libc",
|
||||
|
|
@ -467,9 +467,9 @@ checksum = "18794a8ad5b29321f790b55d93dfba91e125cb1a9edbd4f8e3150acc771c1a5e"
|
|||
|
||||
[[package]]
|
||||
name = "libgit2-sys"
|
||||
version = "0.12.19+1.1.0"
|
||||
version = "0.12.20+1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f322155d574c8b9ebe991a04f6908bb49e68a79463338d24a43d6274cb6443e6"
|
||||
checksum = "1e2f09917e00b9ad194ae72072bb5ada2cca16d8171a43e91ddba2afbb02664b"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"libc",
|
||||
|
|
@ -666,9 +666,9 @@ checksum = "af8b08b04175473088b46763e51ee54da5f9a164bc162f615b91bc179dbf15a3"
|
|||
|
||||
[[package]]
|
||||
name = "openssl-probe"
|
||||
version = "0.1.2"
|
||||
version = "0.1.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "77af24da69f9d9341038eba93a073b1fdaaa1b788221b00a69bce9e762cb32de"
|
||||
checksum = "28988d872ab76095a6e6ac88d99b54fd267702734fd7ffe610ca27f533ddb95a"
|
||||
|
||||
[[package]]
|
||||
name = "openssl-src"
|
||||
|
|
|
|||
|
|
@ -14,6 +14,8 @@ keywords = ["git"]
|
|||
[dependencies]
|
||||
scopetime = { path = "../scopetime", version = "0.1" }
|
||||
git2 = { version = "0.13", features = ["vendored-openssl"] }
|
||||
# git2 = { path = "../../github/git2-rs", features = ["vendored-openssl"]}
|
||||
# git2 = { git="https://github.com/extrawurst/git2-rs.git", rev="513a8c9", features = ["vendored-openssl"]}
|
||||
rayon-core = "1.9"
|
||||
crossbeam-channel = "0.5"
|
||||
log = "0.4"
|
||||
|
|
|
|||
|
|
@ -1,10 +1,25 @@
|
|||
use crate::{
|
||||
error::{Error, Result},
|
||||
sync::{reset_stage, reset_workdir, utils},
|
||||
sync::{reset_stage, reset_workdir, utils, CommitId},
|
||||
};
|
||||
use git2::{BranchType, MergeOptions};
|
||||
use scopetime::scope_time;
|
||||
|
||||
///
|
||||
pub fn merge_state_info(repo_path: &str) -> Result<Vec<CommitId>> {
|
||||
scope_time!("merge_state_info");
|
||||
|
||||
let mut repo = utils::repo(repo_path)?;
|
||||
|
||||
let mut ids: Vec<CommitId> = Vec::new();
|
||||
repo.mergehead_foreach(|id| {
|
||||
ids.push(CommitId::from(*id));
|
||||
true
|
||||
})?;
|
||||
|
||||
Ok(ids)
|
||||
}
|
||||
|
||||
/// does these steps:
|
||||
/// * reset all staged changes,
|
||||
/// * revert all changes in workdir
|
||||
|
|
@ -47,3 +62,32 @@ pub fn merge_branch(repo_path: &str, branch: &str) -> Result<()> {
|
|||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::sync::{
|
||||
create_branch,
|
||||
tests::{repo_init, write_commit_file},
|
||||
};
|
||||
|
||||
#[test]
|
||||
fn test_smoke() {
|
||||
let (_td, repo) = repo_init().unwrap();
|
||||
let root = repo.path().parent().unwrap();
|
||||
let repo_path = root.as_os_str().to_str().unwrap();
|
||||
|
||||
let c1 =
|
||||
write_commit_file(&repo, "test.txt", "test", "commit1");
|
||||
|
||||
create_branch(repo_path, "foo").unwrap();
|
||||
|
||||
write_commit_file(&repo, "test.txt", "test2", "commit2");
|
||||
|
||||
merge_branch(repo_path, "master").unwrap();
|
||||
|
||||
let mergeheads = merge_state_info(repo_path).unwrap();
|
||||
|
||||
assert_eq!(mergeheads[0], c1);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ pub use hooks::{
|
|||
pub use hunks::{reset_hunk, stage_hunk, unstage_hunk};
|
||||
pub use ignore::add_to_ignore;
|
||||
pub use logwalker::LogWalker;
|
||||
pub use merge::{abort_merge, merge_branch};
|
||||
pub use merge::{abort_merge, merge_branch, merge_state_info};
|
||||
pub use remotes::{
|
||||
get_default_remote, get_remotes, push::AsyncProgress,
|
||||
tags::PushTagsProgress,
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ use asyncgit::{
|
|||
};
|
||||
use crossbeam_channel::Sender;
|
||||
use crossterm::event::Event;
|
||||
use itertools::Itertools;
|
||||
use std::convert::Into;
|
||||
use std::convert::TryFrom;
|
||||
use tui::{
|
||||
|
|
@ -214,9 +215,19 @@ impl Status {
|
|||
f: &mut tui::Frame<B>,
|
||||
r: tui::layout::Rect,
|
||||
) -> Result<()> {
|
||||
if let Ok(state) = asyncgit::sync::repo_state(CWD) {
|
||||
if let Ok(state) = sync::repo_state(CWD) {
|
||||
if state != RepoState::Clean {
|
||||
let txt = format!("{:?}", state);
|
||||
let ids =
|
||||
sync::merge_state_info(CWD).unwrap_or_default();
|
||||
let ids = format!(
|
||||
"({})",
|
||||
ids.iter()
|
||||
.map(|id| sync::CommitId::get_short_string(
|
||||
id
|
||||
))
|
||||
.join(",")
|
||||
);
|
||||
let txt = format!("{:?} {}", state, ids);
|
||||
let txt_len = u16::try_from(txt.len())?;
|
||||
let w = Paragraph::new(txt)
|
||||
.style(Style::default().fg(Color::Red))
|
||||
|
|
|
|||
Loading…
Reference in a new issue