Skip to content

Commit 66dee9a

Browse files
committed
Merge branch 'inferiorhumanorgans-repo-status-additional-tests'
2 parents 3617ff4 + 5044576 commit 66dee9a

16 files changed

+185
-31
lines changed

git-repository/src/lib.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -321,31 +321,25 @@ pub mod state {
321321
#[derive(Debug, PartialEq)]
322322
pub enum InProgress {
323323
/// A mailbox is being applied.
324-
// TODO: test
325324
ApplyMailbox,
326325
/// A rebase is happening while a mailbox is being applied.
327326
// TODO: test
328327
ApplyMailboxRebase,
329328
/// A git bisect operation has not yet been concluded.
330-
// TODO: test
331329
Bisect,
332330
/// A cherry pick operation.
333331
CherryPick,
334332
/// A cherry pick with multiple commits pending.
335-
// TODO: test
336333
CherryPickSequence,
337334
/// A merge operation.
338-
// TODO: test
339335
Merge,
340336
/// A rebase operation.
341-
// TODO: test
342337
Rebase,
343338
/// An interactive rebase operation.
344339
RebaseInteractive,
345340
/// A revert operation.
346341
Revert,
347342
/// A revert operation with multiple commits pending.
348-
// TODO: test
349343
RevertSequence,
350344
}
351345
}

git-repository/src/repository/reference.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,11 @@ impl crate::Repository {
200200
.map_err(Into::into)
201201
}
202202

203+
/// Return the name to the symbolic reference `HEAD` points to, or `None` if the head is detached.
204+
pub fn head_name(&self) -> Result<Option<git_ref::FullName>, crate::reference::find::existing::Error> {
205+
Ok(self.head()?.referent_name().map(|n| n.to_owned()))
206+
}
207+
203208
/// Return the commit object the `HEAD` reference currently points to after peeling it fully.
204209
///
205210
/// Note that this may fail for various reasons, most notably because the repository

git-repository/src/repository/state.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ use crate::state;
33
impl crate::Repository {
44
/// Returns the status of an in progress operation on a repository or [`None`]
55
/// if no operation is currently in progress.
6-
pub fn in_progress_operation(&self) -> Option<state::InProgress> {
6+
///
7+
/// Note to be confused with the repositories 'status'.
8+
pub fn state(&self) -> Option<state::InProgress> {
79
let git_dir = self.path();
810

911
// This is modeled on the logic from wt_status_get_state in git's wt-status.c and
@@ -20,7 +22,7 @@ impl crate::Repository {
2022
} else if git_dir.join("rebase-merge").is_dir() {
2123
Some(state::InProgress::Rebase)
2224
} else if git_dir.join("CHERRY_PICK_HEAD").is_file() {
23-
if git_dir.join("todo").is_file() {
25+
if git_dir.join("sequencer/todo").is_file() {
2426
Some(state::InProgress::CherryPickSequence)
2527
} else {
2628
Some(state::InProgress::CherryPick)
@@ -30,7 +32,7 @@ impl crate::Repository {
3032
} else if git_dir.join("BISECT_LOG").is_file() {
3133
Some(state::InProgress::Bisect)
3234
} else if git_dir.join("REVERT_HEAD").is_file() {
33-
if git_dir.join("todo").is_file() {
35+
if git_dir.join("sequencer/todo").is_file() {
3436
Some(state::InProgress::RevertSequence)
3537
} else {
3638
Some(state::InProgress::Revert)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:357c85ba0f2c4e8703e643ebbebc49229d0560eb0e6ed1ffa08969d4750f5bc5
3+
size 11356
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:6e38aff8e6054660ffa274ff00ad8398601949576d887e0cc462256f16e966bb
3+
size 10200
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:4c3187949760fe07a5abc1a5b7f303ba060bedaed1bfad29535b93df72ca453c
3+
size 11336
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:a61b3a205b9254579ea67390a9b3da43ab9d26b6576555da566ba69ea07aaa3b
3+
size 10948
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:4b76a63be1b90ff164633c074caf3ce3ccfd73ed6f587a7a02e7c039af065519
2+
oid sha256:b44df1ace634ca3f4e4c05911d4bf949777b6037ba3fbb25f4a139d5048d33d0
33
size 10440
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:60a892477189310fa935d43dbaa73d92b3079cbf86023e83262db6000b7556c0
3+
size 11224
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
set -eu -o pipefail
3+
4+
git init -q
5+
6+
echo file.main > file
7+
git add file
8+
git commit -m file.main file
9+
10+
git checkout -b other-branch
11+
echo file.other-branch > file
12+
git commit -m file.other-branch file
13+
# Create an mbox formatted patch and save the path
14+
patch_path=$(git format-patch main)
15+
16+
git checkout main
17+
# Create a conflict
18+
echo file.main.update > file
19+
git commit -m file.main.update file
20+
21+
# This will fail due to the merge conflict and leave us in a 'apply mbox in progress' state
22+
git am 0001-file.other-branch.patch || true
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
set -eu -o pipefail
3+
4+
git init -q
5+
6+
touch f1 f2
7+
8+
git add f1
9+
git commit -m f1 f1
10+
11+
git add f2
12+
git commit -m f2 f2
13+
14+
git bisect start
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
set -eu -o pipefail
3+
4+
git init -q
5+
6+
touch f1 f2 f3
7+
8+
git add f1
9+
git commit -m f1 f1
10+
11+
git checkout -b other-branch
12+
echo f2.other-branch > f2
13+
git add f2
14+
git commit -m f2.other-branch f2
15+
git add f3
16+
git commit -m f3 f3
17+
18+
git checkout main
19+
echo f2.main > f2
20+
git add f2
21+
git commit -m f2.main f2
22+
23+
# This should fail and leave us in a cherry-pick + sequencer state
24+
git cherry-pick other-branch~2..other-branch || true
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
set -eu -o pipefail
3+
4+
git init -q
5+
6+
echo file.main > file
7+
git add file
8+
git commit -m file.main file
9+
10+
git checkout -b other-branch
11+
echo file.other-branch > file
12+
git add file
13+
git commit -m file.other-branch file
14+
15+
git checkout main
16+
echo file.main changed > file
17+
git commit -m file.main\ changed file
18+
19+
git merge other-branch || true

git-repository/tests/fixtures/make_revert_repo.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ set -eu -o pipefail
33

44
git init -q
55

6-
touch 1 2 3
7-
git add 1
8-
git commit -m 1 1
9-
git add 2
10-
git commit -m 2 2
11-
git add 3
12-
git commit -m 3 3
6+
touch f1 f2 f3
7+
git add f1
8+
git commit -m f1 f1
9+
git add f2
10+
git commit -m f2 f2
11+
git add f3
12+
git commit -m f3 f3
1313
git revert --no-commit HEAD~1
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
set -eu -o pipefail
3+
4+
git init -q
5+
6+
echo 1.0 > 1
7+
git add 1
8+
git commit -m 1.0 1
9+
10+
echo 1.1 > 1
11+
git commit -m 1.1 1
12+
13+
echo 1.2 > 1
14+
git commit -m 1.2 1
15+
touch 2
16+
git add 2
17+
git commit -m 2 2
18+
19+
# This should fail and leave us in a revert + sequencer state
20+
git revert --no-commit HEAD HEAD~2 || true
Lines changed: 53 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,60 @@
11
use crate::{named_repo, Result};
22
use git_repository as git;
33

4+
#[test]
5+
fn apply_mailbox() -> Result {
6+
let repo = named_repo("make_am_repo.sh")?;
7+
8+
assert_eq!(repo.head_name()?.unwrap().shorten(), "main");
9+
assert_eq!(repo.state(), Some(git::state::InProgress::ApplyMailbox));
10+
Ok(())
11+
}
12+
13+
#[test]
14+
fn bisect() -> Result {
15+
let repo = named_repo("make_bisect_repo.sh")?;
16+
17+
assert_eq!(repo.head_name()?.unwrap().shorten(), "main");
18+
assert_eq!(repo.state(), Some(git::state::InProgress::Bisect));
19+
20+
Ok(())
21+
}
22+
423
#[test]
524
fn cherry_pick() -> Result {
625
let repo = named_repo("make_cherry_pick_repo.sh")?;
726

8-
let head = repo.head()?;
9-
let head_name = head.referent_name().expect("no detached head").shorten();
10-
assert_eq!(head_name, "main");
27+
assert_eq!(repo.head_name()?.unwrap().shorten(), "main");
28+
assert_eq!(repo.state(), Some(git::state::InProgress::CherryPick));
29+
Ok(())
30+
}
31+
32+
#[test]
33+
fn cherry_pick_sequence() -> Result {
34+
let repo = named_repo("make_cherry_pick_sequence_repo.sh")?;
35+
36+
assert_eq!(repo.head_name()?.unwrap().shorten(), "main");
37+
assert_eq!(repo.state(), Some(git::state::InProgress::CherryPickSequence));
38+
39+
Ok(())
40+
}
41+
42+
#[test]
43+
fn merge() -> Result {
44+
let repo = named_repo("make_merge_repo.sh")?;
45+
46+
assert_eq!(repo.head_name()?.unwrap().shorten(), "main");
47+
assert_eq!(repo.state(), Some(git::state::InProgress::Merge));
1148

12-
assert_eq!(repo.in_progress_operation(), Some(git::state::InProgress::CherryPick));
1349
Ok(())
1450
}
1551

1652
#[test]
1753
fn rebase_interactive() -> Result {
1854
let repo = named_repo("make_rebase_i_repo.sh")?;
1955

20-
let head = repo.head()?;
21-
assert!(head.is_detached());
22-
assert_eq!(
23-
repo.in_progress_operation(),
24-
Some(git::state::InProgress::RebaseInteractive)
25-
);
56+
assert!(repo.head()?.is_detached());
57+
assert_eq!(repo.state(), Some(git::state::InProgress::RebaseInteractive));
2658

2759
Ok(())
2860
}
@@ -31,11 +63,18 @@ fn rebase_interactive() -> Result {
3163
fn revert() -> Result {
3264
let repo = named_repo("make_revert_repo.sh")?;
3365

34-
let head = repo.head()?;
35-
let head_name = head.referent_name().expect("no detached head").shorten();
36-
assert_eq!(head_name, "main");
66+
assert_eq!(repo.head_name()?.unwrap().shorten(), "main");
67+
assert_eq!(repo.state(), Some(git::state::InProgress::Revert));
68+
69+
Ok(())
70+
}
71+
72+
#[test]
73+
fn revert_sequence() -> Result {
74+
let repo = named_repo("make_revert_sequence_repo.sh")?;
3775

38-
assert_eq!(repo.in_progress_operation(), Some(git::state::InProgress::Revert));
76+
assert_eq!(repo.head_name()?.unwrap().shorten(), "main");
77+
assert_eq!(repo.state(), Some(git::state::InProgress::RevertSequence));
3978

4079
Ok(())
4180
}

0 commit comments

Comments
 (0)