GitStrategy

Trait GitStrategy 

Source
pub trait GitStrategy {
    // Required methods
    fn clean<T>(&self, repository: T) -> Result<()>
       where T: Into<RepositoryLocation>;
    fn clone<T, U>(&self, repository: T, remote: U) -> Result<()>
       where T: Into<RepositoryLocation>,
             U: AsRef<str>;
    fn get_changes<T>(&self, repository: T) -> Result<RepositoryChangeStatus>
       where T: Into<RepositoryLocation>;
}
Expand description

Strategy for all git operations.

Apply git operations on a repository. Operations can return information, or mutate the repository.

§Implementations

StrategyDescription
crate::dev::strategy::git::LocalGitStrategyAccess local git repositories
crate::dev::strategy::git::MockGitStrategyMocking implementation

§See

Required Methods§

Source

fn clean<T>(&self, repository: T) -> Result<()>

Clean the repository from files that are explicitely ignored.

This will not delete uncommitted changes. Rather it will clean files which exists, but are ignored. It’s purpose then is to clean out optional files, for example to optimize disk space.

§Example
use grass::dev::strategy::git::{GitStrategy, GitStrategyError, MockGitStrategy};
let strategy = MockGitStrategy;

fn test_strategy<T: GitStrategy>(strategy: &T) {
    assert_eq!(strategy.clean(("all_good", "first")), Ok(()));

    assert!(matches!(
        strategy.clean(("with_error", "first")),
        Err(GitStrategyError::RepositoryError { .. })
    ));

    assert!(matches!(
        strategy.clean(("with_error", "second")),
        Err(GitStrategyError::FileSystemError { .. })
    ));

    assert!(matches!(
        strategy.clean(("missing", "first")),
        Err(GitStrategyError::RepositoryNotFound { .. })
    ));
}

test_strategy(&strategy);
Source

fn clone<T, U>(&self, repository: T, remote: U) -> Result<()>

Clone a remote repository.

§Todo:
  • Support authentication:
    • SSH
    • Password
    • PAT
§Example
use grass::dev::strategy::git::{GitStrategy, GitStrategyError, MockGitStrategy};
let strategy = MockGitStrategy;

fn test_strategy<T: GitStrategy>(strategy: &T) {
    assert_eq!(strategy.clone(("all_good", "new"), "good_remote"), Ok(()));

    assert!(matches!(
        strategy.clone(("all_good", "first"), "good_remote"),
        Err(GitStrategyError::RepositryExists { .. })
    ));

    assert!(matches!(
        strategy.clone(("missing", "first"), "good_remote"),
        Err(GitStrategyError::RepositoryNotFound { .. })
    ));

    assert!(matches!(
        strategy.clone(("all_good", "new"), "no_access"),
        Err(GitStrategyError::RemoteAuthenticationError { .. })
    ));

    assert!(matches!(
        strategy.clone(("all_good", "new"), "bad_response"),
        Err(GitStrategyError::RemoteFetchError { .. })
    ));
}

test_strategy(&strategy);
Source

fn get_changes<T>(&self, repository: T) -> Result<RepositoryChangeStatus>

Get the change status for a repository.

§Example
use grass::dev::strategy::git::{GitStrategy, MockGitStrategy, RepositoryChangeStatus};
let strategy = MockGitStrategy;

fn test_strategy<T: GitStrategy>(strategy: &T) {
    assert_eq!(
        strategy.get_changes(("with_changes", "first")),
        Ok(RepositoryChangeStatus::UpToDate)
    );

    assert_eq!(
        strategy.get_changes(("with_changes", "second")),
        Ok(RepositoryChangeStatus::NoRepository)
    );

    assert_eq!(
        strategy.get_changes(("with_changes", "third")),
        Ok(RepositoryChangeStatus::UncommittedChanges { num_changes: 9 })
    );
}

test_strategy(&strategy);

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§