diff options
author | Stephan Dilly <dilly.stephan@gmail.com> | 2021-05-11 18:26:12 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-11 18:26:12 +0200 |
commit | f30ec498862115dd9b14aa8b2d1836e00336c43e (patch) | |
tree | 0c6bdb92211debc8e712996404884211d13140c9 | |
parent | bc7cef747c5f2973f788752b3ba9b6b0dc4e4864 (diff) |
show merge head ids in merge state (#697)
-rw-r--r-- | .github/workflows/ci.yml | 2 | ||||
-rw-r--r-- | Cargo.lock | 12 | ||||
-rw-r--r-- | asyncgit/Cargo.toml | 2 | ||||
-rw-r--r-- | asyncgit/src/sync/merge.rs | 46 | ||||
-rw-r--r-- | asyncgit/src/sync/mod.rs | 2 | ||||
-rw-r--r-- | src/tabs/status.rs | 15 |
6 files changed, 68 insertions, 11 deletions
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 24e953ea..1bedeb35 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 @@ -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" diff --git a/asyncgit/Cargo.toml b/asyncgit/Cargo.toml index a3240c21..b1872a65 100644 --- a/asyncgit/Cargo.toml +++ b/asyncgit/Cargo.toml @@ -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" diff --git a/asyncgit/src/sync/merge.rs b/asyncgit/src/sync/merge.rs index c61e7411..323d451b 100644 --- a/asyncgit/src/sync/merge.rs +++ b/asyncgit/src/sync/merge.rs @@ -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); + } +} diff --git a/asyncgit/src/sync/mod.rs b/asyncgit/src/sync/mod.rs index 7bb41c95..94074d96 100644 --- a/asyncgit/src/sync/mod.rs +++ b/asyncgit/src/sync/mod.rs @@ -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, diff --git a/src/tabs/status.rs b/src/tabs/status.rs index cccca383..275dac4b 100644 --- a/src/tabs/status.rs +++ b/src/tabs/status.rs @@ -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)) |