Skip to content

Commit 0010675

Browse files
committed
refactor (#382)
1 parent b91e4bd commit 0010675

File tree

4 files changed

+57
-46
lines changed

4 files changed

+57
-46
lines changed

git-repository/src/lib.rs

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,7 @@ pub enum Path {
192192

193193
///
194194
mod types;
195-
pub use types::{
196-
Commit, DetachedObject, Head, Id, Object, Reference, Repository, RepositoryState, Tag, ThreadSafeRepository, Tree,
197-
};
195+
pub use types::{Commit, DetachedObject, Head, Id, Object, Reference, Repository, Tag, ThreadSafeRepository, Tree};
198196

199197
pub mod commit;
200198
pub mod head;
@@ -317,6 +315,41 @@ pub mod init {
317315
}
318316
}
319317

318+
/// Not to be confused with 'status'.
319+
pub mod state {
320+
/// Tell what operation is currently in progress.
321+
#[derive(Debug, PartialEq)]
322+
pub enum InProgress {
323+
/// A mailbox is being applied.
324+
// TODO: test
325+
ApplyMailbox,
326+
/// A rebase is happening while a mailbox is being applied.
327+
// TODO: test
328+
ApplyMailboxRebase,
329+
/// A git bisect operation has not yet been concluded.
330+
// TODO: test
331+
Bisect,
332+
/// A cherry pick operation.
333+
CherryPick,
334+
/// A cherry pick with multiple commits pending.
335+
// TODO: test
336+
CherryPickSequence,
337+
/// A merge operation.
338+
// TODO: test
339+
Merge,
340+
/// A rebase operation.
341+
// TODO: test
342+
Rebase,
343+
/// An interactive rebase operation.
344+
RebaseInteractive,
345+
/// A revert operation.
346+
Revert,
347+
/// A revert operation with multiple commits pending.
348+
// TODO: test
349+
RevertSequence,
350+
}
351+
}
352+
320353
///
321354
pub mod discover {
322355
use crate::{path, ThreadSafeRepository};

git-repository/src/repository/state.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,39 @@
1-
use crate::RepositoryState;
1+
use crate::state;
22

33
impl crate::Repository {
44
/// Returns the status of an in progress operation on a repository or [`None`]
5-
/// if nothing is happening.
6-
pub fn in_progress_operation(&self) -> Option<RepositoryState> {
5+
/// if no operation is currently in progress.
6+
pub fn in_progress_operation(&self) -> Option<state::InProgress> {
77
let git_dir = self.path();
88

99
// This is modeled on the logic from wt_status_get_state in git's wt-status.c and
1010
// ps1 from git-prompt.sh.
1111

1212
if git_dir.join("rebase-apply/applying").is_file() {
13-
Some(RepositoryState::ApplyMailbox)
13+
Some(state::InProgress::ApplyMailbox)
1414
} else if git_dir.join("rebase-apply/rebasing").is_file() {
15-
Some(RepositoryState::Rebase)
15+
Some(state::InProgress::Rebase)
1616
} else if git_dir.join("rebase-apply").is_dir() {
17-
Some(RepositoryState::ApplyMailboxRebase)
17+
Some(state::InProgress::ApplyMailboxRebase)
1818
} else if git_dir.join("rebase-merge/interactive").is_file() {
19-
Some(RepositoryState::RebaseInteractive)
19+
Some(state::InProgress::RebaseInteractive)
2020
} else if git_dir.join("rebase-merge").is_dir() {
21-
Some(RepositoryState::Rebase)
21+
Some(state::InProgress::Rebase)
2222
} else if git_dir.join("CHERRY_PICK_HEAD").is_file() {
2323
if git_dir.join("todo").is_file() {
24-
Some(RepositoryState::CherryPickSequence)
24+
Some(state::InProgress::CherryPickSequence)
2525
} else {
26-
Some(RepositoryState::CherryPick)
26+
Some(state::InProgress::CherryPick)
2727
}
2828
} else if git_dir.join("MERGE_HEAD").is_file() {
29-
Some(RepositoryState::Merge)
29+
Some(state::InProgress::Merge)
3030
} else if git_dir.join("BISECT_LOG").is_file() {
31-
Some(RepositoryState::Bisect)
31+
Some(state::InProgress::Bisect)
3232
} else if git_dir.join("REVERT_HEAD").is_file() {
3333
if git_dir.join("todo").is_file() {
34-
Some(RepositoryState::RevertSequence)
34+
Some(state::InProgress::RevertSequence)
3535
} else {
36-
Some(RepositoryState::Revert)
36+
Some(state::InProgress::Revert)
3737
}
3838
} else {
3939
None

git-repository/src/types.rs

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -124,31 +124,6 @@ pub struct Repository {
124124
pub(crate) config: crate::config::Cache,
125125
}
126126

127-
/// The state of a git repository
128-
#[derive(Debug, PartialEq)]
129-
pub enum RepositoryState {
130-
/// Apply mailbox in progress
131-
ApplyMailbox,
132-
/// Rebase while an apply mailbox operation is in progress
133-
ApplyMailboxRebase,
134-
/// Bisect in progress
135-
Bisect,
136-
/// Cherry pick operation in progress
137-
CherryPick,
138-
/// Cherry pick with multiple commits pending in the sequencer in progress
139-
CherryPickSequence,
140-
/// Merge operation in progress
141-
Merge,
142-
/// Rebase in progress
143-
Rebase,
144-
/// Interactive rebase in progress
145-
RebaseInteractive,
146-
/// Revert operation in progress
147-
Revert,
148-
/// Revert operation with multiple commits pending in the sequencer in progress
149-
RevertSequence,
150-
}
151-
152127
/// An instance with access to everything a git repository entails, best imagined as container implementing `Sync + Send` for _most_
153128
/// for system resources required to interact with a `git` repository which are loaded in once the instance is created.
154129
///

git-repository/tests/repository/state.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::{named_repo, Result};
2-
use git_repository::RepositoryState;
2+
use git_repository as git;
33

44
#[test]
55
fn cherry_pick() -> Result {
@@ -9,7 +9,7 @@ fn cherry_pick() -> Result {
99
let head_name = head.referent_name().expect("no detached head").shorten();
1010
assert_eq!(head_name, "main");
1111

12-
assert_eq!(repo.in_progress_operation(), Some(RepositoryState::CherryPick));
12+
assert_eq!(repo.in_progress_operation(), Some(git::state::InProgress::CherryPick));
1313
Ok(())
1414
}
1515

@@ -19,7 +19,10 @@ fn rebase_interactive() -> Result {
1919

2020
let head = repo.head()?;
2121
assert!(head.is_detached());
22-
assert_eq!(repo.in_progress_operation(), Some(RepositoryState::RebaseInteractive));
22+
assert_eq!(
23+
repo.in_progress_operation(),
24+
Some(git::state::InProgress::RebaseInteractive)
25+
);
2326

2427
Ok(())
2528
}
@@ -32,7 +35,7 @@ fn revert() -> Result {
3235
let head_name = head.referent_name().expect("no detached head").shorten();
3336
assert_eq!(head_name, "main");
3437

35-
assert_eq!(Some(RepositoryState::Revert), repo.in_progress_operation());
38+
assert_eq!(repo.in_progress_operation(), Some(git::state::InProgress::Revert));
3639

3740
Ok(())
3841
}

0 commit comments

Comments
 (0)