Skip to content

More test coverage for Repository::state::InProgress #393

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

Closed
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
6 changes: 0 additions & 6 deletions git-repository/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,31 +321,25 @@ pub mod state {
#[derive(Debug, PartialEq)]
pub enum InProgress {
/// A mailbox is being applied.
// TODO: test
ApplyMailbox,
/// A rebase is happening while a mailbox is being applied.
// TODO: test
ApplyMailboxRebase,
/// A git bisect operation has not yet been concluded.
// TODO: test
Bisect,
/// A cherry pick operation.
CherryPick,
/// A cherry pick with multiple commits pending.
// TODO: test
CherryPickSequence,
/// A merge operation.
// TODO: test
Merge,
/// A rebase operation.
// TODO: test
Rebase,
/// An interactive rebase operation.
RebaseInteractive,
/// A revert operation.
Revert,
/// A revert operation with multiple commits pending.
// TODO: test
RevertSequence,
}
}
Expand Down
4 changes: 2 additions & 2 deletions git-repository/src/repository/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl crate::Repository {
} else if git_dir.join("rebase-merge").is_dir() {
Some(state::InProgress::Rebase)
} else if git_dir.join("CHERRY_PICK_HEAD").is_file() {
if git_dir.join("todo").is_file() {
if git_dir.join("sequencer/todo").is_file() {
Some(state::InProgress::CherryPickSequence)
} else {
Some(state::InProgress::CherryPick)
Expand All @@ -30,7 +30,7 @@ impl crate::Repository {
} else if git_dir.join("BISECT_LOG").is_file() {
Some(state::InProgress::Bisect)
} else if git_dir.join("REVERT_HEAD").is_file() {
if git_dir.join("todo").is_file() {
if git_dir.join("sequencer/todo").is_file() {
Some(state::InProgress::RevertSequence)
} else {
Some(state::InProgress::Revert)
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
22 changes: 22 additions & 0 deletions git-repository/tests/fixtures/make_am_repo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash
set -eu -o pipefail

git init -q

echo 1.main > 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue I am having with naming files with numbers while redirecting into them is that … >1 has a different meaning than > 1, and it's just a little too close for me to feel comfortable while reading the script.

I hope you can see the point and avoid such names in the future, and I am happy to rename it for you for now as well.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, the joys of sh. The only thing I'd add is that for this script I saved the path to the patch in ${patch_path} but the call to git am references the file directly.

The latter should be git am "${patch_path}".

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the hint. It's adjusted in cfaf31f.

git add 1
git commit -m 1.main 1

git checkout -b other-branch
echo 1.other-branch > 1
git commit -m 1.other-branch 1
# Create an mbox formatted patch and save the path
patch_path=$(git format-patch main)

git checkout main
# Create a conflict
echo 1.main.update > 1
git commit -m 1.main.update 1

# This will fail due to the merge conflict and leave us in a 'apply mbox in progress' state
git am 0001-1.other-branch.patch || true
14 changes: 14 additions & 0 deletions git-repository/tests/fixtures/make_bisect_repo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash
set -eu -o pipefail

git init -q

touch 1 2

git add 1
git commit -m 1 1

git add 2
git commit -m 2 2

git bisect start
24 changes: 24 additions & 0 deletions git-repository/tests/fixtures/make_cherry_pick_sequence_repo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash
set -eu -o pipefail

git init -q

touch 1 2 3

git add 1
git commit -m 1 1

git checkout -b other-branch
echo 2.other-branch > 2
git add 2
git commit -m 2.other-branch 2
git add 3
git commit -m 3 3

git checkout main
echo 2.main > 2
git add 2
git commit -m 2.main 2

# This should fail and leave us in a cherry-pick + sequencer state
git cherry-pick other-branch~2..other-branch || true
19 changes: 19 additions & 0 deletions git-repository/tests/fixtures/make_merge_repo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash
set -eu -o pipefail

git init -q

echo 1.main > 1
git add 1
git commit -m 1.main 1

git checkout -b other-branch
echo 1.other-branch > 1
git add 1
git commit -m 1.other-branch 1

git checkout main
echo 1.main changed > 1
git commit -m 1.main\ changed 1

git merge other-branch || true
20 changes: 20 additions & 0 deletions git-repository/tests/fixtures/make_revert_sequence_repo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash
set -eu -o pipefail

git init -q

echo 1.0 > 1
git add 1
git commit -m 1.0 1

echo 1.1 > 1
git commit -m 1.1 1

echo 1.2 > 1
git commit -m 1.2 1
touch 2
git add 2
git commit -m 2 2

# This should fail and leave us in a revert + sequencer state
git revert --no-commit HEAD HEAD~2 || true
70 changes: 70 additions & 0 deletions git-repository/tests/repository/state.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,31 @@
use crate::{named_repo, Result};
use git_repository as git;

#[test]
fn apply_mailbox() -> Result {
let repo = named_repo("make_am_repo.sh")?;

let head = repo.head()?;
let head_name = head.referent_name().expect("no detached head").shorten();
assert_eq!(head_name, "main");

assert_eq!(repo.in_progress_operation(), Some(git::state::InProgress::ApplyMailbox));
Ok(())
}

#[test]
fn bisect() -> Result {
let repo = named_repo("make_bisect_repo.sh")?;

let head = repo.head()?;
let head_name = head.referent_name().expect("no detached head").shorten();
assert_eq!(head_name, "main");

assert_eq!(repo.in_progress_operation(), Some(git::state::InProgress::Bisect));

Ok(())
}

#[test]
fn cherry_pick() -> Result {
let repo = named_repo("make_cherry_pick_repo.sh")?;
Expand All @@ -13,6 +38,35 @@ fn cherry_pick() -> Result {
Ok(())
}

#[test]
fn cherry_pick_sequence() -> Result {
let repo = named_repo("make_cherry_pick_sequence_repo.sh")?;

let head = repo.head()?;
let head_name = head.referent_name().expect("no detached head").shorten();
assert_eq!(head_name, "main");

assert_eq!(
repo.in_progress_operation(),
Some(git::state::InProgress::CherryPickSequence)
);

Ok(())
}

#[test]
fn merge() -> Result {
let repo = named_repo("make_merge_repo.sh")?;

let head = repo.head()?;
let head_name = head.referent_name().expect("no detached head").shorten();
assert_eq!(head_name, "main");

assert_eq!(repo.in_progress_operation(), Some(git::state::InProgress::Merge));

Ok(())
}

#[test]
fn rebase_interactive() -> Result {
let repo = named_repo("make_rebase_i_repo.sh")?;
Expand All @@ -39,3 +93,19 @@ fn revert() -> Result {

Ok(())
}

#[test]
fn revert_sequence() -> Result {
let repo = named_repo("make_revert_sequence_repo.sh")?;

let head = repo.head()?;
let head_name = head.referent_name().expect("no detached head").shorten();
assert_eq!(head_name, "main");

assert_eq!(
repo.in_progress_operation(),
Some(git::state::InProgress::RevertSequence)
);

Ok(())
}