Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 3 additions & 1 deletion git-repository/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,9 @@ pub enum Path {

///
mod types;
pub use types::{Commit, DetachedObject, Head, Id, Object, Reference, Repository, Tag, ThreadSafeRepository, Tree};
pub use types::{
Commit, DetachedObject, Head, Id, Object, Reference, Repository, RepositoryState, Tag, ThreadSafeRepository, Tree,
};

pub mod commit;
pub mod head;
Expand Down
2 changes: 2 additions & 0 deletions git-repository/src/repository/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ mod location;

mod snapshots;

mod state;

mod impls;

mod cache;
Expand Down
42 changes: 42 additions & 0 deletions git-repository/src/repository/state.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
use crate::RepositoryState;

impl crate::Repository {
/// Returns the status of an in progress operation on a repository or [`RepositoryState::None`]
/// if nothing is happening.
pub fn in_progress_operation(&self) -> RepositoryState {
let repo_path = self.path();

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

if repo_path.join("rebase-apply/applying").is_file() {
return RepositoryState::ApplyMailbox;
} else if repo_path.join("rebase-apply/rebasing").is_file() {
return RepositoryState::Rebase;
} else if repo_path.join("rebase-apply").is_dir() {
return RepositoryState::ApplyMailboxRebase;
} else if repo_path.join("rebase-merge/interactive").is_file() {
return RepositoryState::RebaseInteractive;
} else if repo_path.join("rebase-merge").is_dir() {
return RepositoryState::Rebase;
} else if repo_path.join("CHERRY_PICK_HEAD").is_file() {
if repo_path.join("todo").is_file() {
return RepositoryState::CherryPickSequence;
} else {
return RepositoryState::CherryPick;
}
} else if repo_path.join("MERGE_HEAD").is_file() {
return RepositoryState::Merge;
} else if repo_path.join("BISECT_LOG").is_file() {
return RepositoryState::Bisect;
} else if repo_path.join("REVERT_HEAD").is_file() {
if repo_path.join("todo").is_file() {
return RepositoryState::RevertSequence;
} else {
return RepositoryState::Revert;
}
} else {
return RepositoryState::None;
}
}
}
27 changes: 27 additions & 0 deletions git-repository/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,33 @@ pub struct Repository {
pub(crate) config: crate::config::Cache,
}

/// The state of a git repository
#[derive(Debug, PartialEq)]
pub enum RepositoryState {
/// No operations are in progress
None,
/// Apply mailbox in progress
ApplyMailbox,
/// Rebase while an apply mailbox operation is in progress
ApplyMailboxRebase,
/// Bisect in progress
Bisect,
/// Cherry pick operation in progress
CherryPick,
/// Cherry pick with multiple commits pending in the sequencer in progress
CherryPickSequence,
/// Merge operation in progress
Merge,
/// Rebase in progress
Rebase,
/// Interactive rebase in progress
RebaseInteractive,
/// Revert operation in progress
Revert,
/// Revert operation with multiple commits pending in the sequencer in progress
RevertSequence,
}

/// An instance with access to everything a git repository entails, best imagined as container implementing `Sync + Send` for _most_
/// for system resources required to interact with a `git` repository which are loaded in once the instance is created.
///
Expand Down