diff --git a/src/git/mod.rs b/src/git/mod.rs index 42c0321716..0a6e87658e 100644 --- a/src/git/mod.rs +++ b/src/git/mod.rs @@ -279,9 +279,6 @@ pub(crate) fn commit_fixup_cmd(reference: &str) -> Command { pub(crate) fn pull_cmd() -> Command { git(&["pull"]) } -pub(crate) fn fetch_all_cmd() -> Command { - git(&["fetch", "--all"]) -} pub(crate) fn rebase_interactive_cmd(reference: &str) -> Command { git(&["rebase", "-i", "--autostash", reference]) } diff --git a/src/git/remote.rs b/src/git/remote.rs index 6bfb5a9284..d99cbab01c 100644 --- a/src/git/remote.rs +++ b/src/git/remote.rs @@ -1,14 +1,56 @@ use crate::Res; +use git2::FetchOptions; use git2::PushOptions; use git2::RemoteCallbacks; use git2::Repository; +pub(crate) fn fetch_upstream(repo: &Repository) -> Res { + let Ok(head) = repo.head() else { + return Err(Box::new(RemoteError::NoHead)); + }; + let Ok(upstream) = repo.branch_upstream_remote(head.name().unwrap()) else { + return Err(Box::new(RemoteError::NoUpstreamRemote)); + }; + + fetch(repo, repo.find_remote(upstream.as_str().unwrap()).unwrap()) +} + +pub(crate) fn fetch_all(repo: &Repository) -> Res { + for remote in repo.remotes()?.iter().flatten() { + fetch(repo, repo.find_remote(remote).unwrap())?; + } + + Ok("Fetched all".to_string()) +} + +fn fetch(repo: &Repository, mut remote: git2::Remote<'_>) -> Res { + { + let mut opts = FetchOptions::new(); + let mut callbacks = RemoteCallbacks::new(); + callbacks.credentials(|url, username_from_url, allowed_types| { + auth_git2::GitAuthenticator::default().credentials(&repo.config()?)( + url, + username_from_url, + allowed_types, + ) + }); + + opts.remote_callbacks(callbacks); + + let refspec_array = &remote.fetch_refspecs()?; + let refspecs = refspec_array.into_iter().flatten().collect::>(); + remote.fetch::<&str>(&refspecs, Some(&mut opts), None)?; + }; + + Ok(format!("Fetched {}", remote.name().unwrap())) +} + pub(crate) fn push_upstream(repo: &Repository) -> Res { let Ok(head) = repo.head() else { - return Err(Box::new(PushError::NoHead)); + return Err(Box::new(RemoteError::NoHead)); }; let Ok(upstream) = repo.branch_upstream_remote(head.name().unwrap()) else { - return Err(Box::new(PushError::NoUpstreamRemote)); + return Err(Box::new(RemoteError::NoUpstreamRemote)); }; let mut remote = repo.find_remote(upstream.as_str().unwrap()).unwrap(); @@ -36,27 +78,27 @@ pub(crate) fn push_upstream(repo: &Repository) -> Res { } if let Some(status) = out_status { - return Err(Box::new(PushError::ResponseStatus(status))); + return Err(Box::new(RemoteError::ResponseStatus(status))); } Ok(format!("Pushed {} to {}", out_name, remote.name().unwrap())) } #[derive(Debug)] -pub(crate) enum PushError { +pub(crate) enum RemoteError { NoHead, NoUpstreamRemote, ResponseStatus(String), } -impl std::fmt::Display for PushError { +impl std::fmt::Display for RemoteError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.write_str(match self { - PushError::NoHead => "No head", - PushError::NoUpstreamRemote => "No upstream remote", - PushError::ResponseStatus(status) => status, + RemoteError::NoHead => "No head", + RemoteError::NoUpstreamRemote => "No upstream remote", + RemoteError::ResponseStatus(status) => status, }) } } -impl std::error::Error for PushError {} +impl std::error::Error for RemoteError {} diff --git a/src/keybinds.rs b/src/keybinds.rs index f5ac4ba94d..2c9c0c1132 100644 --- a/src/keybinds.rs +++ b/src/keybinds.rs @@ -102,15 +102,16 @@ pub(crate) const KEYBINDS: &[Keybind] = &[ // Fetch Keybind::nomod(None, Char('f'), Submenu(Fetch)), Keybind::nomod(Fetch, Char('a'), FetchAll), + Keybind::nomod(Fetch, Char('u'), FetchUpstream), // Log Keybind::nomod(None, Char('l'), Submenu(Log)), Keybind::nomod(Log, Char('l'), LogCurrent), // Pull Keybind::shift(None, Char('F'), Submenu(Pull)), - Keybind::nomod(Pull, Char('p'), PullRemote), + Keybind::nomod(Pull, Char('u'), PullUpstream), // Push Keybind::shift(None, Char('P'), Submenu(Push)), - Keybind::nomod(Push, Char('u'), PushUpstreamRemote), + Keybind::nomod(Push, Char('u'), PushUpstream), // Rebase Keybind::nomod(None, Char('r'), Submenu(Rebase)), Keybind::nomod(Rebase, Char('i'), Target(RebaseInteractive)), @@ -138,12 +139,13 @@ pub(crate) enum Op { ToggleSection, HalfPageUp, HalfPageDown, - PushUpstreamRemote, - PullRemote, + PushUpstream, + PullUpstream, Submenu(SubmenuOp), Commit, CommitAmend, FetchAll, + FetchUpstream, LogCurrent, RebaseAbort, RebaseContinue, diff --git a/src/lib.rs b/src/lib.rs index b353041214..457b1a252a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -264,11 +264,14 @@ fn handle_op( } Submenu(op) => state.pending_submenu_op = op, LogCurrent => goto_log_screen(Rc::clone(&state.repo), &mut state.screens), - FetchAll => { - state.run_external_cmd(terminal, &[], git::fetch_all_cmd())?; - } - PullRemote => state.run_external_cmd(terminal, &[], git::pull_cmd())?, - PushUpstreamRemote => state.run_cmd(terminal, "git push", |state| { + FetchAll => state.run_cmd(terminal, "git fetch --all", |state| { + git::remote::fetch_all(&state.repo) + })?, + FetchUpstream => state.run_cmd(terminal, "git fetch", |state| { + git::remote::fetch_upstream(&state.repo) + })?, + PullUpstream => state.run_external_cmd(terminal, &[], git::pull_cmd())?, + PushUpstream => state.run_cmd(terminal, "git push", |state| { git::remote::push_upstream(&state.repo) })?, Target(target_op) => { @@ -422,41 +425,41 @@ mod tests { use crossterm::event::{Event, KeyCode, KeyEvent, KeyModifiers}; use git2::Repository; use ratatui::{backend::TestBackend, prelude::Rect, Terminal}; - use std::{env, fs, process::Command}; + use std::{env, fs, path::Path, process::Command}; use temp_dir::TempDir; #[test] fn no_repo() { - let (ref mut terminal, state, _dir, _remote_dir) = setup(60, 20); + let (ref mut terminal, state, _dir) = setup_init(60, 20); insta::assert_snapshot!(redact_hashes(terminal, &state.repo)); } #[test] fn help_menu() { - let (ref mut terminal, ref mut state, _dir, _remote_dir) = setup(60, 20); + let (ref mut terminal, ref mut state, _dir) = setup_init(60, 20); update(terminal, state, &[key('h')]).unwrap(); insta::assert_snapshot!(redact_hashes(terminal, &state.repo)); } #[test] fn fresh_init() { - let (ref mut terminal, ref mut state, _dir, _remote_dir) = setup(60, 20); + let (ref mut terminal, ref mut state, _dir) = setup_init(60, 20); update(terminal, state, &[key('g')]).unwrap(); insta::assert_snapshot!(redact_hashes(terminal, &state.repo)); } #[test] fn new_file() { - let (ref mut terminal, ref mut state, dir, _remote_dir) = setup(60, 20); - run(&dir, &["touch", "new-file"]); + let (ref mut terminal, ref mut state, dir) = setup_init(60, 20); + run(dir.path(), &["touch", "new-file"]); update(terminal, state, &[key('g')]).unwrap(); insta::assert_snapshot!(redact_hashes(terminal, &state.repo)); } #[test] fn unstaged_changes() { - let (ref mut terminal, ref mut state, dir, _remote_dir) = setup(60, 20); - commit(&dir, "testfile", "testing\ntesttest"); + let (ref mut terminal, ref mut state, dir) = setup_init(60, 20); + commit(dir.path(), "testfile", "testing\ntesttest"); fs::write(dir.child("testfile"), "test\ntesttest").expect("error writing to file"); update(terminal, state, &[key('g')]).unwrap(); @@ -465,26 +468,26 @@ mod tests { #[test] fn staged_file() { - let (ref mut terminal, ref mut state, dir, _remote_dir) = setup(60, 20); - run(&dir, &["touch", "new-file"]); - run(&dir, &["git", "add", "new-file"]); + let (ref mut terminal, ref mut state, dir) = setup_init(60, 20); + run(dir.path(), &["touch", "new-file"]); + run(dir.path(), &["git", "add", "new-file"]); update(terminal, state, &[key('g')]).unwrap(); insta::assert_snapshot!(redact_hashes(terminal, &state.repo)); } #[test] fn log() { - let (ref mut terminal, ref mut state, dir, _remote_dir) = setup(60, 20); - commit(&dir, "firstfile", "testing\ntesttest\n"); - commit(&dir, "secondfile", "testing\ntesttest\n"); + let (ref mut terminal, ref mut state, dir, _remote_dir) = setup_clone(60, 20); + commit(dir.path(), "firstfile", "testing\ntesttest\n"); + commit(dir.path(), "secondfile", "testing\ntesttest\n"); update(terminal, state, &[key('g'), key('l'), key('l')]).unwrap(); insta::assert_snapshot!(redact_hashes(terminal, &state.repo)); } #[test] fn show() { - let (ref mut terminal, ref mut state, dir, _remote_dir) = setup(60, 20); - commit(&dir, "firstfile", "This should be visible\n"); + let (ref mut terminal, ref mut state, dir, _remote_dir) = setup_clone(60, 20); + commit(dir.path(), "firstfile", "This should be visible\n"); update( terminal, state, @@ -496,17 +499,17 @@ mod tests { #[test] fn rebase_conflict() { - let (ref mut terminal, ref mut state, dir, _remote_dir) = setup(60, 20); - commit(&dir, "new-file", "hello"); + let (ref mut terminal, ref mut state, dir, _remote_dir) = setup_clone(60, 20); + commit(dir.path(), "new-file", "hello"); - run(&dir, &["git", "checkout", "-b", "other-branch"]); - commit(&dir, "new-file", "hey"); + run(dir.path(), &["git", "checkout", "-b", "other-branch"]); + commit(dir.path(), "new-file", "hey"); - run(&dir, &["git", "checkout", "main"]); - commit(&dir, "new-file", "hi"); + run(dir.path(), &["git", "checkout", "main"]); + commit(dir.path(), "new-file", "hi"); - run(&dir, &["git", "checkout", "other-branch"]); - run(&dir, &["git", "rebase", "main"]); + run(dir.path(), &["git", "checkout", "other-branch"]); + run(dir.path(), &["git", "rebase", "main"]); update(terminal, state, &[key('g')]).unwrap(); insta::assert_snapshot!(redact_hashes(terminal, &state.repo)); @@ -514,16 +517,16 @@ mod tests { #[test] fn merge_conflict() { - let (ref mut terminal, ref mut state, dir, _remote_dir) = setup(60, 20); - commit(&dir, "new-file", "hello"); + let (ref mut terminal, ref mut state, dir, _remote_dir) = setup_clone(60, 20); + commit(dir.path(), "new-file", "hello"); - run(&dir, &["git", "checkout", "-b", "other-branch"]); - commit(&dir, "new-file", "hey"); + run(dir.path(), &["git", "checkout", "-b", "other-branch"]); + commit(dir.path(), "new-file", "hey"); - run(&dir, &["git", "checkout", "main"]); - commit(&dir, "new-file", "hi"); + run(dir.path(), &["git", "checkout", "main"]); + commit(dir.path(), "new-file", "hi"); - run(&dir, &["git", "merge", "other-branch"]); + run(dir.path(), &["git", "merge", "other-branch"]); update(terminal, state, &[key('g')]).unwrap(); insta::assert_snapshot!(redact_hashes(terminal, &state.repo)); @@ -531,9 +534,9 @@ mod tests { #[test] fn moved_file() { - let (ref mut terminal, ref mut state, dir, _remote_dir) = setup(60, 20); - commit(&dir, "new-file", "hello"); - run(&dir, &["git", "mv", "new-file", "moved-file"]); + let (ref mut terminal, ref mut state, dir, _remote_dir) = setup_clone(60, 20); + commit(dir.path(), "new-file", "hello"); + run(dir.path(), &["git", "mv", "new-file", "moved-file"]); update(terminal, state, &[key('g')]).unwrap(); insta::assert_snapshot!(redact_hashes(terminal, &state.repo)); @@ -541,19 +544,19 @@ mod tests { #[test] fn hide_untracked() { - let (ref mut terminal, ref mut state, dir, _remote_dir) = setup(60, 10); + let (ref mut terminal, ref mut state, dir, _remote_dir) = setup_clone(60, 10); let mut config = state.repo.config().unwrap(); config.set_str("status.showUntrackedFiles", "off").unwrap(); - run(&dir, &["touch", "i-am-untracked"]); + run(dir.path(), &["touch", "i-am-untracked"]); update(terminal, state, &[key('g')]).unwrap(); insta::assert_snapshot!(redact_hashes(terminal, &state.repo)); } #[test] - fn commit_from_empty() { - let (ref mut terminal, ref mut state, dir, _remote_dir) = setup(60, 10); - commit(&dir, "new-file", ""); + fn new_commit() { + let (ref mut terminal, ref mut state, dir, _remote_dir) = setup_clone(60, 10); + commit(dir.path(), "new-file", ""); update(terminal, state, &[key('g')]).unwrap(); insta::assert_snapshot!(redact_hashes(terminal, &state.repo)); @@ -561,39 +564,69 @@ mod tests { #[test] fn push() { - let (ref mut terminal, ref mut state, dir, _remote_dir) = setup(60, 10); - commit(&dir, "new-file", ""); + let (ref mut terminal, ref mut state, dir, _remote_dir) = setup_clone(60, 10); + commit(dir.path(), "new-file", ""); update(terminal, state, &[key('P'), key('u')]).unwrap(); insta::assert_snapshot!(redact_hashes(terminal, &state.repo)); } #[test] - fn unpushed() { - let (ref mut terminal, ref mut state, dir, _remote_dir) = setup(60, 10); - commit(&dir, "new-file", ""); - update(terminal, state, &[key('P'), key('u')]).unwrap(); - commit(&dir, "another-file", ""); + fn fetch_upstream() { + let (ref mut terminal, ref mut state, _dir, remote_dir) = setup_clone(60, 10); + clone_and_commit(&remote_dir, "remote-file", "hello"); - update(terminal, state, &[key('g')]).unwrap(); + update(terminal, state, &[key('f'), key('u')]).unwrap(); + insta::assert_snapshot!(redact_hashes(terminal, &state.repo)); + } + + #[test] + fn fetch_all() { + let (ref mut terminal, ref mut state, _dir, remote_dir) = setup_clone(60, 10); + clone_and_commit(&remote_dir, "remote-file", "hello"); + + update(terminal, state, &[key('f'), key('a')]).unwrap(); insta::assert_snapshot!(redact_hashes(terminal, &state.repo)); } - fn setup(width: u16, height: u16) -> (Terminal, State, TempDir, TempDir) { + fn setup_init(width: u16, height: u16) -> (Terminal, State, TempDir) { let terminal = Terminal::new(TestBackend::new(width, height)).unwrap(); - let remote_dir = TempDir::new().unwrap(); let dir = TempDir::new().unwrap(); - env::set_var("GIT_CONFIG_GLOBAL", "/dev/null"); - env::set_var("GIT_CONFIG_SYSTEM", "/dev/null"); - env::set_var("GIT_COMMITTER_DATE", "Sun Feb 18 14:00 2024 +0100"); + set_env_vars(); + run(dir.path(), &["git", "init", "--initial-branch=main"]); + let state = State::create( + Repository::open(dir.path()).unwrap(), + crate::Config { + dir: dir.path().into(), + }, + Rect::new(0, 0, width, height), + Args { + command: None, + status: false, + exit_immediately: false, + }, + ) + .unwrap(); + + set_config(state.repo.config().unwrap()); + (terminal, state, dir) + } + + fn setup_clone(width: u16, height: u16) -> (Terminal, State, TempDir, TempDir) { + let terminal = Terminal::new(TestBackend::new(width, height)).unwrap(); + let remote_dir = TempDir::new().unwrap(); + let dir = TempDir::new().unwrap(); + + set_env_vars(); run( - &remote_dir, + remote_dir.path(), &["git", "init", "--bare", "--initial-branch=main"], ); + clone_and_commit(&remote_dir, "initial-file", "hello"); run( - &dir, + dir.path(), &["git", "clone", remote_dir.path().to_str().unwrap(), "."], ); @@ -611,15 +644,39 @@ mod tests { ) .unwrap(); - let mut config = state.repo.config().unwrap(); + set_config(state.repo.config().unwrap()); + (terminal, state, dir, remote_dir) + } + + fn clone_and_commit(remote_dir: &TempDir, file_name: &str, file_content: &str) { + let other_dir = TempDir::new().unwrap(); + + run( + other_dir.path(), + &["git", "clone", remote_dir.path().to_str().unwrap(), "."], + ); + + let other_repo = Repository::open(other_dir.path()).unwrap(); + set_config(other_repo.config().unwrap()); + + commit(other_dir.path(), file_name, file_content); + run(other_dir.path(), &["git", "push"]); + } + + fn set_env_vars() { + env::set_var("GIT_CONFIG_GLOBAL", "/dev/null"); + env::set_var("GIT_CONFIG_SYSTEM", "/dev/null"); + env::set_var("GIT_COMMITTER_DATE", "Sun Feb 18 14:00 2024 +0100"); + } + + fn set_config(mut config: git2::Config) { config.set_str("user.email", "ci@example.com").unwrap(); config.set_str("user.name", "CI").unwrap(); - - (terminal, state, dir, remote_dir) } - fn commit(dir: &TempDir, file_name: &str, contents: &str) { - let path = dir.child(file_name); + fn commit(dir: &Path, file_name: &str, contents: &str) { + let mut path = dir.to_path_buf(); + path.push(file_name); let message = match path.try_exists() { Ok(true) => format!("modify {}\n\nCommit body goes here\n", file_name), _ => format!("add {}\n\nCommit body goes here\n", file_name), @@ -629,10 +686,10 @@ mod tests { run(dir, &["git", "commit", "-m", &message]); } - fn run(dir: &TempDir, cmd: &[&str]) { + fn run(dir: &Path, cmd: &[&str]) { Command::new(cmd[0]) .args(&cmd[1..]) - .current_dir(dir.path()) + .current_dir(dir) .output() .unwrap_or_else(|_| panic!("failed to execute {:?}", cmd)); } diff --git a/src/snapshots/gitu__tests__fetch_all.snap b/src/snapshots/gitu__tests__fetch_all.snap new file mode 100644 index 0000000000..bfbedb1cbd --- /dev/null +++ b/src/snapshots/gitu__tests__fetch_all.snap @@ -0,0 +1,35 @@ +--- +source: src/lib.rs +expression: "redact_hashes(terminal, &state.repo)" +--- +Buffer { + area: Rect { x: 0, y: 0, width: 60, height: 10 }, + content: [ + "πŸ’’On branch main ", + " Your branch is behind 'origin/main' by 1 commit. ", + " ", + " Recent commits ", + " _______ main add initial-file ", + " ", + " ", + "────────────────────────────────────────────────────────────", + "$ git fetch --all ", + "Fetched all ", + ], + styles: [ + x: 0, y: 0, fg: Reset, bg: Rgb(80, 73, 69), underline: Reset, modifier: NONE, + x: 1, y: 0, fg: Rgb(216, 166, 87), bg: Rgb(80, 73, 69), underline: Reset, modifier: BOLD, + x: 15, y: 0, fg: Reset, bg: Rgb(80, 73, 69), underline: Reset, modifier: NONE, + x: 0, y: 1, fg: Reset, bg: Rgb(42, 40, 39), underline: Reset, modifier: NONE, + x: 0, y: 2, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, + x: 1, y: 3, fg: Rgb(216, 166, 87), bg: Reset, underline: Reset, modifier: BOLD, + x: 15, y: 3, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, + x: 1, y: 4, fg: Rgb(216, 166, 87), bg: Reset, underline: Reset, modifier: NONE, + x: 8, y: 4, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, + x: 9, y: 4, fg: Rgb(169, 182, 101), bg: Reset, underline: Reset, modifier: NONE, + x: 13, y: 4, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, + x: 0, y: 7, fg: Rgb(80, 73, 69), bg: Reset, underline: Reset, modifier: NONE, + x: 0, y: 8, fg: Rgb(125, 174, 163), bg: Reset, underline: Reset, modifier: NONE, + x: 17, y: 8, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, + ] +} diff --git a/src/snapshots/gitu__tests__fetch_upstream.snap b/src/snapshots/gitu__tests__fetch_upstream.snap new file mode 100644 index 0000000000..58d9978086 --- /dev/null +++ b/src/snapshots/gitu__tests__fetch_upstream.snap @@ -0,0 +1,35 @@ +--- +source: src/lib.rs +expression: "redact_hashes(terminal, &state.repo)" +--- +Buffer { + area: Rect { x: 0, y: 0, width: 60, height: 10 }, + content: [ + "πŸ’’On branch main ", + " Your branch is behind 'origin/main' by 1 commit. ", + " ", + " Recent commits ", + " _______ main add initial-file ", + " ", + " ", + "────────────────────────────────────────────────────────────", + "$ git fetch ", + "Fetched origin ", + ], + styles: [ + x: 0, y: 0, fg: Reset, bg: Rgb(80, 73, 69), underline: Reset, modifier: NONE, + x: 1, y: 0, fg: Rgb(216, 166, 87), bg: Rgb(80, 73, 69), underline: Reset, modifier: BOLD, + x: 15, y: 0, fg: Reset, bg: Rgb(80, 73, 69), underline: Reset, modifier: NONE, + x: 0, y: 1, fg: Reset, bg: Rgb(42, 40, 39), underline: Reset, modifier: NONE, + x: 0, y: 2, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, + x: 1, y: 3, fg: Rgb(216, 166, 87), bg: Reset, underline: Reset, modifier: BOLD, + x: 15, y: 3, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, + x: 1, y: 4, fg: Rgb(216, 166, 87), bg: Reset, underline: Reset, modifier: NONE, + x: 8, y: 4, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, + x: 9, y: 4, fg: Rgb(169, 182, 101), bg: Reset, underline: Reset, modifier: NONE, + x: 13, y: 4, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, + x: 0, y: 7, fg: Rgb(80, 73, 69), bg: Reset, underline: Reset, modifier: NONE, + x: 0, y: 8, fg: Rgb(125, 174, 163), bg: Reset, underline: Reset, modifier: NONE, + x: 11, y: 8, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, + ] +} diff --git a/src/snapshots/gitu__tests__hide_untracked.snap b/src/snapshots/gitu__tests__hide_untracked.snap index c43656c361..c4ba83a8aa 100644 --- a/src/snapshots/gitu__tests__hide_untracked.snap +++ b/src/snapshots/gitu__tests__hide_untracked.snap @@ -1,15 +1,15 @@ --- source: src/lib.rs -expression: "redact_hashes(terminal, dir)" +expression: "redact_hashes(terminal, &state.repo)" --- Buffer { area: Rect { x: 0, y: 0, width: 60, height: 10 }, content: [ - "πŸ’’No branch ", + "πŸ’’On branch main ", + " Your branch is up to date with 'origin/main'. ", " ", " Recent commits ", - " ", - " ", + " _______ main origin/main add initial-file ", " ", " ", " ", @@ -19,9 +19,16 @@ Buffer { styles: [ x: 0, y: 0, fg: Reset, bg: Rgb(80, 73, 69), underline: Reset, modifier: NONE, x: 1, y: 0, fg: Rgb(216, 166, 87), bg: Rgb(80, 73, 69), underline: Reset, modifier: BOLD, - x: 10, y: 0, fg: Reset, bg: Rgb(80, 73, 69), underline: Reset, modifier: NONE, - x: 0, y: 1, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, - x: 1, y: 2, fg: Rgb(216, 166, 87), bg: Reset, underline: Reset, modifier: BOLD, - x: 15, y: 2, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, + x: 15, y: 0, fg: Reset, bg: Rgb(80, 73, 69), underline: Reset, modifier: NONE, + x: 0, y: 1, fg: Reset, bg: Rgb(42, 40, 39), underline: Reset, modifier: NONE, + x: 0, y: 2, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, + x: 1, y: 3, fg: Rgb(216, 166, 87), bg: Reset, underline: Reset, modifier: BOLD, + x: 15, y: 3, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, + x: 1, y: 4, fg: Rgb(216, 166, 87), bg: Reset, underline: Reset, modifier: NONE, + x: 8, y: 4, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, + x: 9, y: 4, fg: Rgb(169, 182, 101), bg: Reset, underline: Reset, modifier: NONE, + x: 13, y: 4, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, + x: 14, y: 4, fg: Rgb(234, 105, 98), bg: Reset, underline: Reset, modifier: NONE, + x: 25, y: 4, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, ] } diff --git a/src/snapshots/gitu__tests__log.snap b/src/snapshots/gitu__tests__log.snap index 3bfa82fb5e..2b078fb0f9 100644 --- a/src/snapshots/gitu__tests__log.snap +++ b/src/snapshots/gitu__tests__log.snap @@ -7,7 +7,7 @@ Buffer { content: [ "πŸ’’_______ main add secondfile ", " _______ add firstfile ", - " ", + " _______ origin/main add initial-file ", " ", " ", " ", @@ -35,5 +35,9 @@ Buffer { x: 0, y: 1, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, x: 1, y: 1, fg: Rgb(216, 166, 87), bg: Reset, underline: Reset, modifier: NONE, x: 8, y: 1, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, + x: 1, y: 2, fg: Rgb(216, 166, 87), bg: Reset, underline: Reset, modifier: NONE, + x: 8, y: 2, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, + x: 9, y: 2, fg: Rgb(234, 105, 98), bg: Reset, underline: Reset, modifier: NONE, + x: 20, y: 2, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, ] } diff --git a/src/snapshots/gitu__tests__merge_conflict.snap b/src/snapshots/gitu__tests__merge_conflict.snap index 020541e4b8..925972e4d4 100644 --- a/src/snapshots/gitu__tests__merge_conflict.snap +++ b/src/snapshots/gitu__tests__merge_conflict.snap @@ -19,7 +19,7 @@ Buffer { " Recent commits ", " _______ main modify new-file ", " _______ add new-file ", - " ", + " _______ origin/main add initial-file ", " ", " ", " ", @@ -51,5 +51,9 @@ Buffer { x: 13, y: 12, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, x: 1, y: 13, fg: Rgb(216, 166, 87), bg: Reset, underline: Reset, modifier: NONE, x: 8, y: 13, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, + x: 1, y: 14, fg: Rgb(216, 166, 87), bg: Reset, underline: Reset, modifier: NONE, + x: 8, y: 14, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, + x: 9, y: 14, fg: Rgb(234, 105, 98), bg: Reset, underline: Reset, modifier: NONE, + x: 20, y: 14, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, ] } diff --git a/src/snapshots/gitu__tests__moved_file.snap b/src/snapshots/gitu__tests__moved_file.snap index 7788ae911d..2484d44f7b 100644 --- a/src/snapshots/gitu__tests__moved_file.snap +++ b/src/snapshots/gitu__tests__moved_file.snap @@ -6,7 +6,7 @@ Buffer { area: Rect { x: 0, y: 0, width: 60, height: 20 }, content: [ "πŸ’’On branch main ", - " Your branch is based on 'origin/main', but the upstream is…", + " Your branch is ahead of 'origin/main' by 1 commit. ", " ", " Staged changes (2) ", " moved-file ", @@ -18,7 +18,7 @@ Buffer { " ", " Recent commits ", " _______ main add new-file ", - " ", + " _______ origin/main add initial-file ", " ", " ", " ", @@ -52,5 +52,9 @@ Buffer { x: 8, y: 12, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, x: 9, y: 12, fg: Rgb(169, 182, 101), bg: Reset, underline: Reset, modifier: NONE, x: 13, y: 12, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, + x: 1, y: 13, fg: Rgb(216, 166, 87), bg: Reset, underline: Reset, modifier: NONE, + x: 8, y: 13, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, + x: 9, y: 13, fg: Rgb(234, 105, 98), bg: Reset, underline: Reset, modifier: NONE, + x: 20, y: 13, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, ] } diff --git a/src/snapshots/gitu__tests__new_commit.snap b/src/snapshots/gitu__tests__new_commit.snap new file mode 100644 index 0000000000..c0fe914c88 --- /dev/null +++ b/src/snapshots/gitu__tests__new_commit.snap @@ -0,0 +1,36 @@ +--- +source: src/lib.rs +expression: "redact_hashes(terminal, &state.repo)" +--- +Buffer { + area: Rect { x: 0, y: 0, width: 60, height: 10 }, + content: [ + "πŸ’’On branch main ", + " Your branch is ahead of 'origin/main' by 1 commit. ", + " ", + " Recent commits ", + " _______ main add new-file ", + " _______ origin/main add initial-file ", + " ", + " ", + " ", + " ", + ], + styles: [ + x: 0, y: 0, fg: Reset, bg: Rgb(80, 73, 69), underline: Reset, modifier: NONE, + x: 1, y: 0, fg: Rgb(216, 166, 87), bg: Rgb(80, 73, 69), underline: Reset, modifier: BOLD, + x: 15, y: 0, fg: Reset, bg: Rgb(80, 73, 69), underline: Reset, modifier: NONE, + x: 0, y: 1, fg: Reset, bg: Rgb(42, 40, 39), underline: Reset, modifier: NONE, + x: 0, y: 2, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, + x: 1, y: 3, fg: Rgb(216, 166, 87), bg: Reset, underline: Reset, modifier: BOLD, + x: 15, y: 3, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, + x: 1, y: 4, fg: Rgb(216, 166, 87), bg: Reset, underline: Reset, modifier: NONE, + x: 8, y: 4, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, + x: 9, y: 4, fg: Rgb(169, 182, 101), bg: Reset, underline: Reset, modifier: NONE, + x: 13, y: 4, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, + x: 1, y: 5, fg: Rgb(216, 166, 87), bg: Reset, underline: Reset, modifier: NONE, + x: 8, y: 5, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, + x: 9, y: 5, fg: Rgb(234, 105, 98), bg: Reset, underline: Reset, modifier: NONE, + x: 20, y: 5, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, + ] +} diff --git a/src/snapshots/gitu__tests__new_file.snap b/src/snapshots/gitu__tests__new_file.snap index 7caf38917f..27e25f1aa0 100644 --- a/src/snapshots/gitu__tests__new_file.snap +++ b/src/snapshots/gitu__tests__new_file.snap @@ -1,6 +1,6 @@ --- source: src/lib.rs -expression: "redact_hashes(terminal, dir)" +expression: "redact_hashes(terminal, &state.repo)" --- Buffer { area: Rect { x: 0, y: 0, width: 60, height: 20 }, diff --git a/src/snapshots/gitu__tests__push.snap b/src/snapshots/gitu__tests__push.snap index aa292d2f69..6cac96e8ea 100644 --- a/src/snapshots/gitu__tests__push.snap +++ b/src/snapshots/gitu__tests__push.snap @@ -10,7 +10,7 @@ Buffer { " ", " Recent commits ", " _______ main origin/main add new-file ", - " ", + " _______ add initial-file ", " ", "────────────────────────────────────────────────────────────", "$ git push ", @@ -30,6 +30,8 @@ Buffer { x: 13, y: 4, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, x: 14, y: 4, fg: Rgb(234, 105, 98), bg: Reset, underline: Reset, modifier: NONE, x: 25, y: 4, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, + x: 1, y: 5, fg: Rgb(216, 166, 87), bg: Reset, underline: Reset, modifier: NONE, + x: 8, y: 5, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, x: 0, y: 7, fg: Rgb(80, 73, 69), bg: Reset, underline: Reset, modifier: NONE, x: 0, y: 8, fg: Rgb(125, 174, 163), bg: Reset, underline: Reset, modifier: NONE, x: 10, y: 8, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, diff --git a/src/snapshots/gitu__tests__rebase_conflict.snap b/src/snapshots/gitu__tests__rebase_conflict.snap index e3c03e52e3..54e6a9f337 100644 --- a/src/snapshots/gitu__tests__rebase_conflict.snap +++ b/src/snapshots/gitu__tests__rebase_conflict.snap @@ -19,7 +19,7 @@ Buffer { " Recent commits ", " _______ main modify new-file ", " _______ add new-file ", - " ", + " _______ origin/main add initial-file ", " ", " ", " ", @@ -51,5 +51,9 @@ Buffer { x: 13, y: 12, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, x: 1, y: 13, fg: Rgb(216, 166, 87), bg: Reset, underline: Reset, modifier: NONE, x: 8, y: 13, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, + x: 1, y: 14, fg: Rgb(216, 166, 87), bg: Reset, underline: Reset, modifier: NONE, + x: 8, y: 14, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, + x: 9, y: 14, fg: Rgb(234, 105, 98), bg: Reset, underline: Reset, modifier: NONE, + x: 20, y: 14, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, ] } diff --git a/src/snapshots/gitu__tests__staged_file.snap b/src/snapshots/gitu__tests__staged_file.snap index 6bc86f9e81..d3025974d1 100644 --- a/src/snapshots/gitu__tests__staged_file.snap +++ b/src/snapshots/gitu__tests__staged_file.snap @@ -1,6 +1,6 @@ --- source: src/lib.rs -expression: "redact_hashes(terminal, dir)" +expression: "redact_hashes(terminal, &state.repo)" --- Buffer { area: Rect { x: 0, y: 0, width: 60, height: 20 }, diff --git a/src/snapshots/gitu__tests__unstaged_changes.snap b/src/snapshots/gitu__tests__unstaged_changes.snap index 5c46561b20..3590ff9f6e 100644 --- a/src/snapshots/gitu__tests__unstaged_changes.snap +++ b/src/snapshots/gitu__tests__unstaged_changes.snap @@ -6,7 +6,6 @@ Buffer { area: Rect { x: 0, y: 0, width: 60, height: 20 }, content: [ "πŸ’’On branch main ", - " Your branch is based on 'origin/main', but the upstream is…", " ", " Unstaged changes (1) ", " testfile ", @@ -25,30 +24,30 @@ Buffer { " ", " ", " ", + " ", ], styles: [ x: 0, y: 0, fg: Reset, bg: Rgb(80, 73, 69), underline: Reset, modifier: NONE, x: 1, y: 0, fg: Rgb(216, 166, 87), bg: Rgb(80, 73, 69), underline: Reset, modifier: BOLD, x: 15, y: 0, fg: Reset, bg: Rgb(80, 73, 69), underline: Reset, modifier: NONE, - x: 0, y: 1, fg: Reset, bg: Rgb(42, 40, 39), underline: Reset, modifier: NONE, - x: 0, y: 2, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, - x: 1, y: 3, fg: Rgb(216, 166, 87), bg: Reset, underline: Reset, modifier: BOLD, - x: 21, y: 3, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, - x: 1, y: 4, fg: Rgb(211, 134, 155), bg: Reset, underline: Reset, modifier: BOLD, - x: 9, y: 4, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, - x: 1, y: 5, fg: Rgb(125, 174, 163), bg: Reset, underline: Reset, modifier: NONE, - x: 16, y: 5, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, - x: 1, y: 6, fg: Rgb(234, 105, 98), bg: Reset, underline: Reset, modifier: NONE, - x: 2, y: 6, fg: Rgb(234, 105, 98), bg: Reset, underline: Reset, modifier: REVERSED, - x: 9, y: 6, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, - x: 1, y: 7, fg: Rgb(169, 182, 101), bg: Reset, underline: Reset, modifier: NONE, - x: 2, y: 7, fg: Rgb(169, 182, 101), bg: Reset, underline: Reset, modifier: REVERSED, - x: 6, y: 7, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, - x: 1, y: 10, fg: Rgb(216, 166, 87), bg: Reset, underline: Reset, modifier: BOLD, - x: 15, y: 10, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, - x: 1, y: 11, fg: Rgb(216, 166, 87), bg: Reset, underline: Reset, modifier: NONE, - x: 8, y: 11, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, - x: 9, y: 11, fg: Rgb(169, 182, 101), bg: Reset, underline: Reset, modifier: NONE, - x: 13, y: 11, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, + x: 0, y: 1, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, + x: 1, y: 2, fg: Rgb(216, 166, 87), bg: Reset, underline: Reset, modifier: BOLD, + x: 21, y: 2, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, + x: 1, y: 3, fg: Rgb(211, 134, 155), bg: Reset, underline: Reset, modifier: BOLD, + x: 9, y: 3, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, + x: 1, y: 4, fg: Rgb(125, 174, 163), bg: Reset, underline: Reset, modifier: NONE, + x: 16, y: 4, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, + x: 1, y: 5, fg: Rgb(234, 105, 98), bg: Reset, underline: Reset, modifier: NONE, + x: 2, y: 5, fg: Rgb(234, 105, 98), bg: Reset, underline: Reset, modifier: REVERSED, + x: 9, y: 5, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, + x: 1, y: 6, fg: Rgb(169, 182, 101), bg: Reset, underline: Reset, modifier: NONE, + x: 2, y: 6, fg: Rgb(169, 182, 101), bg: Reset, underline: Reset, modifier: REVERSED, + x: 6, y: 6, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, + x: 1, y: 9, fg: Rgb(216, 166, 87), bg: Reset, underline: Reset, modifier: BOLD, + x: 15, y: 9, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, + x: 1, y: 10, fg: Rgb(216, 166, 87), bg: Reset, underline: Reset, modifier: NONE, + x: 8, y: 10, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, + x: 9, y: 10, fg: Rgb(169, 182, 101), bg: Reset, underline: Reset, modifier: NONE, + x: 13, y: 10, fg: Reset, bg: Reset, underline: Reset, modifier: NONE, ] }