Skip to content

Merge heads #697

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 9 commits into from
May 11, 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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions asyncgit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
46 changes: 45 additions & 1 deletion asyncgit/src/sync/merge.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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);
}
}
2 changes: 1 addition & 1 deletion asyncgit/src/sync/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
15 changes: 13 additions & 2 deletions src/tabs/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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))
Expand Down