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
| Strategy | Description |
|---|---|
| crate::dev::strategy::git::LocalGitStrategy | Access local git repositories |
| crate::dev::strategy::git::MockGitStrategy | Mocking implementation |
§See
Required Methods§
Sourcefn clean<T>(&self, repository: T) -> Result<()>where
T: Into<RepositoryLocation>,
fn clean<T>(&self, repository: T) -> Result<()>where
T: Into<RepositoryLocation>,
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);Sourcefn clone<T, U>(&self, repository: T, remote: U) -> Result<()>
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);Sourcefn get_changes<T>(&self, repository: T) -> Result<RepositoryChangeStatus>where
T: Into<RepositoryLocation>,
fn get_changes<T>(&self, repository: T) -> Result<RepositoryChangeStatus>where
T: Into<RepositoryLocation>,
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.