feat: default diffs to branch changes
This commit is contained in:
+126
-1
@@ -7,7 +7,11 @@ use std::{
|
||||
time::{Duration, Instant},
|
||||
};
|
||||
|
||||
use vamp::{diff::Phase, editor::Input, session::EditorSession};
|
||||
use vamp::{
|
||||
diff::{ComparisonMode, Phase},
|
||||
editor::Input,
|
||||
session::EditorSession,
|
||||
};
|
||||
|
||||
static NEXT: AtomicU64 = AtomicU64::new(0);
|
||||
|
||||
@@ -111,6 +115,10 @@ fn typed_diff_edits_unsaved_working_after_and_preserves_undo_on_explicit_close()
|
||||
session.handle(Input::Enter);
|
||||
assert_eq!(session.editor().diff().unwrap().phase, Phase::After);
|
||||
session.handle(Input::Enter);
|
||||
assert_eq!(
|
||||
session.editor().diff().unwrap().comparison_mode,
|
||||
ComparisonMode::Snapshots
|
||||
);
|
||||
wait_until(&mut session, |session| {
|
||||
session
|
||||
.editor()
|
||||
@@ -485,3 +493,120 @@ fn readonly_jump_history_restores_the_comparison_file_and_source_cursor() {
|
||||
fs::read_to_string(root.join("first.rs")).unwrap()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn branch_changes_default_and_mode_switches_compare_the_selected_divergent_tips() {
|
||||
let fixture = Fixture::new();
|
||||
let root = fixture.0.join("repo");
|
||||
fixture.git(&["init", "-q"]);
|
||||
fs::write(root.join("common"), "common\n").unwrap();
|
||||
fixture.git(&["add", "."]);
|
||||
fixture.git(&["commit", "-qm", "common"]);
|
||||
let base = fixture.git(&["rev-parse", "HEAD"]);
|
||||
fs::write(root.join("base-only"), "base branch\n").unwrap();
|
||||
fixture.git(&["add", "."]);
|
||||
fixture.git(&["commit", "-qm", "base only"]);
|
||||
let before = fixture.git(&["rev-parse", "HEAD"]);
|
||||
fixture.git(&["checkout", "-qb", "feature", &base]);
|
||||
fs::write(root.join("feature-only"), "feature branch\n").unwrap();
|
||||
fixture.git(&["add", "."]);
|
||||
fixture.git(&["commit", "-qm", "feature only"]);
|
||||
let after = fixture.git(&["rev-parse", "HEAD"]);
|
||||
let config = fixture.0.join("config.rb");
|
||||
fs::write(&config, "Vamp.configure do |config|\n config.clipboard_mode = 'separate'\n config.bind 'ctrl+b', config.core.diff.mode.toggle\nend\n").unwrap();
|
||||
let mut session =
|
||||
EditorSession::open(Some(root.join("common")), vec![], Some(&config)).unwrap();
|
||||
session.execute("diff");
|
||||
wait_until(&mut session, |session| {
|
||||
!session.editor().diff().unwrap().loading
|
||||
});
|
||||
assert_eq!(
|
||||
session.editor().diff().unwrap().comparison_mode,
|
||||
ComparisonMode::BranchChanges
|
||||
);
|
||||
session.handle(Input::Ctrl('b'));
|
||||
assert_eq!(
|
||||
session.editor().diff().unwrap().comparison_mode,
|
||||
ComparisonMode::Snapshots
|
||||
);
|
||||
session.handle(Input::Ctrl('p'));
|
||||
type_query(&mut session, "diff.mode.toggle");
|
||||
session.handle(Input::Enter);
|
||||
assert_eq!(
|
||||
session.editor().diff().unwrap().comparison_mode,
|
||||
ComparisonMode::BranchChanges
|
||||
);
|
||||
for id in [&before, &after] {
|
||||
type_query(&mut session, id);
|
||||
session.handle(Input::Down);
|
||||
session.handle(Input::Enter);
|
||||
}
|
||||
wait_until(&mut session, |session| {
|
||||
session.editor().diff().unwrap().selected_file_loaded()
|
||||
});
|
||||
let diff = session.editor().diff().unwrap();
|
||||
let comparison = diff.comparison.as_ref().unwrap();
|
||||
assert_eq!(comparison.files.len(), 1);
|
||||
assert_eq!(comparison.files[0].path, Path::new("feature-only"));
|
||||
assert_eq!(comparison.files[0].after, ["feature branch"]);
|
||||
assert_eq!(
|
||||
comparison.before,
|
||||
format!("merge base of {before} and {after} · {base}")
|
||||
);
|
||||
assert_eq!(diff.before.as_ref().unwrap().label, before);
|
||||
|
||||
session.execute("diff.mode.toggle");
|
||||
wait_until(&mut session, |session| {
|
||||
session.editor().diff().unwrap().selected_file_loaded()
|
||||
});
|
||||
let comparison = session
|
||||
.editor()
|
||||
.diff()
|
||||
.unwrap()
|
||||
.comparison
|
||||
.as_ref()
|
||||
.unwrap();
|
||||
assert_eq!(comparison.before, before);
|
||||
assert_eq!(comparison.after, after);
|
||||
assert_eq!(
|
||||
comparison
|
||||
.files
|
||||
.iter()
|
||||
.map(|file| file.path.as_path())
|
||||
.collect::<Vec<_>>(),
|
||||
[Path::new("base-only"), Path::new("feature-only")]
|
||||
);
|
||||
|
||||
// Superseding an in-flight recomparison must not restore the old mode's result.
|
||||
session.execute("diff.mode.toggle");
|
||||
session.execute("diff.mode.toggle");
|
||||
session.execute("diff.mode.toggle");
|
||||
wait_until(&mut session, |session| {
|
||||
session.editor().diff().unwrap().selected_file_loaded()
|
||||
});
|
||||
let diff = session.editor().diff().unwrap();
|
||||
assert_eq!(diff.comparison_mode, ComparisonMode::BranchChanges);
|
||||
assert_eq!(diff.comparison.as_ref().unwrap().files.len(), 1);
|
||||
assert_eq!(diff.before.as_ref().unwrap().label, before);
|
||||
assert_eq!(diff.after.as_ref().unwrap().label, after);
|
||||
session.execute("diff.close");
|
||||
assert_eq!(session.editor().path(), Some(root.join("common").as_path()));
|
||||
|
||||
session.execute("diff");
|
||||
wait_until(&mut session, |session| {
|
||||
!session.editor().diff().unwrap().loading
|
||||
});
|
||||
session.handle(Input::Enter);
|
||||
let diff = session.editor().diff().unwrap();
|
||||
assert_eq!(diff.phase, Phase::After);
|
||||
assert_eq!(diff.comparison_mode, ComparisonMode::Snapshots);
|
||||
session.execute("diff.mode.toggle");
|
||||
assert_eq!(
|
||||
session.editor().diff().unwrap().comparison_mode,
|
||||
ComparisonMode::Snapshots
|
||||
);
|
||||
assert_eq!(
|
||||
session.editor().message(),
|
||||
"Working checkout requires Snapshots"
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user