[−][src]Type Definition radicle_surf::vcs::git::GitBrowser
type GitBrowser<'repo> = Browser<'repo, GitRepository, Commit<'repo>, GitError>;
A Browser
that uses GitRepository
as the underlying repository backend,
git2::Commit
as the artifact, and GitError
for error reporting.
Methods
impl<'repo> GitBrowser<'repo>
[src]
pub fn new(repository: &'repo GitRepository) -> Result<Self, GitError>
[src]
Create a new browser to interact with.
Examples
use radicle_surf::vcs::git::{GitBrowser, GitRepository}; let repo = GitRepository::new("./data/git-platinum").unwrap(); let browser = GitBrowser::new(&repo).unwrap();
pub fn head(&mut self) -> Result<(), GitError>
[src]
Set the current GitBrowser
history to the HEAD
commit of the underlying repository.
Examples
use radicle_surf::vcs::git::{GitBrowser, GitRepository}; let repo = GitRepository::new("./data/git-platinum").unwrap(); let mut browser = GitBrowser::new(&repo).unwrap(); // ensure we're at HEAD browser.head(); let directory = browser.get_directory(); // We are able to render the directory assert!(directory.is_ok());
pub fn branch(&mut self, branch_name: BranchName) -> Result<(), GitError>
[src]
Set the current GitBrowser
history to the BranchName
provided.
Examples
use radicle_surf::vcs::git::{BranchName, GitBrowser, GitRepository}; let repo = GitRepository::new("./data/git-platinum").unwrap(); let mut browser = GitBrowser::new(&repo).unwrap(); // ensure we're on 'master' browser.branch(BranchName::new("master")); let directory = browser.get_directory(); // We are able to render the directory assert!(directory.is_ok());
use radicle_surf::vcs::git::{BranchName, GitBrowser, GitRepository}; use radicle_surf::file_system::{Label, Path, SystemType}; use radicle_surf::file_system::unsound; let repo = GitRepository::new("./data/git-platinum").unwrap(); let mut browser = GitBrowser::new(&repo).unwrap(); browser .branch(BranchName::new("origin/dev")) .expect("Failed to change branch to dev"); let directory = browser.get_directory().expect("Failed to get directory"); let mut directory_contents = directory.list_directory(); directory_contents.sort(); assert_eq!( directory_contents, vec![ SystemType::file(unsound::label::new(".i-am-well-hidden")), SystemType::file(unsound::label::new(".i-too-am-hidden")), SystemType::file(unsound::label::new("README.md")), SystemType::directory(unsound::label::new("bin")), SystemType::file(unsound::label::new("here-we-are-on-a-dev-branch.lol")), SystemType::directory(unsound::label::new("src")), SystemType::directory(unsound::label::new("text")), SystemType::directory(unsound::label::new("this")), ] ); let tests = directory .find_directory(&Path::new(unsound::label::new("bin"))) .expect("bin not found"); let mut tests_contents = tests.list_directory(); tests_contents.sort(); assert_eq!( tests_contents, vec![ SystemType::file(unsound::label::new("cat")), SystemType::file(unsound::label::new("ls")), SystemType::file(unsound::label::new("test")), ] );
pub fn tag(&mut self, tag_name: TagName) -> Result<(), GitError>
[src]
Set the current GitBrowser
history to the TagName
provided.
Examples
use git2::Oid; use radicle_surf::vcs::History; use radicle_surf::vcs::git::{TagName, GitBrowser, GitRepository}; let repo = GitRepository::new("./data/git-platinum").unwrap(); let mut browser = GitBrowser::new(&repo).unwrap(); // Switch to "v0.3.0" browser.tag(TagName::new("v0.3.0")).expect("Failed to switch tag"); let expected_history = History(( Oid::from_str("19bec071db6474af89c866a1bd0e4b1ff76e2b97").unwrap(), vec![ Oid::from_str("f3a089488f4cfd1a240a9c01b3fcc4c34a4e97b2").unwrap(), Oid::from_str("2429f097664f9af0c5b7b389ab998b2199ffa977").unwrap(), Oid::from_str("d3464e33d75c75c99bfb90fa2e9d16efc0b7d0e3").unwrap(), ] ).into()); let history_ids = browser.get_history().map(|commit| commit.id()); // We are able to render the directory assert_eq!(history_ids, expected_history);
pub fn commit(&mut self, sha: Sha1) -> Result<(), GitError>
[src]
Set the current GitBrowser
history to the Sha1
provided. The history will consist of a single Commit
.
Examples
use radicle_surf::file_system::{Label, SystemType}; use radicle_surf::vcs::git::{GitBrowser, GitRepository, Sha1}; use radicle_surf::file_system::unsound; let repo = GitRepository::new("./data/git-platinum") .expect("Could not retrieve ./data/git-platinum as git repository"); let mut browser = GitBrowser::new(&repo).expect("Could not initialise Browser"); // Set to the initial commit browser .commit(Sha1::new("e24124b7538658220b5aaf3b6ef53758f0a106dc")) .expect("Missing commit"); let directory = browser.get_directory().unwrap(); let mut directory_contents = directory.list_directory(); directory_contents.sort(); // We should only have src in our root assert_eq!( directory_contents, vec![ SystemType::file(unsound::label::new("README.md")), SystemType::directory(unsound::label::new("bin")), SystemType::directory(unsound::label::new("src")), SystemType::directory(unsound::label::new("this")), ] ); // We have the single commit assert!(browser.get_history().0.len() == 1);
pub fn list_branches(
&self,
filter: Option<BranchType>
) -> Result<Vec<Branch>, GitError>
[src]
&self,
filter: Option<BranchType>
) -> Result<Vec<Branch>, GitError>
List the names of the branches that are contained in the
underlying GitRepository
.
Examples
use radicle_surf::vcs::git::{Branch, BranchName, GitBrowser, GitRepository}; use radicle_surf::vcs::git::git2::BranchType; let repo = GitRepository::new("./data/git-platinum").unwrap(); let mut browser = GitBrowser::new(&repo).unwrap(); let branches = browser.list_branches(None).unwrap(); // 'master' exists in the list of branches assert!(branches.contains(&Branch::local(BranchName::new("master")))); // Filter the branches by `Remote`. let mut branches = browser.list_branches(Some(BranchType::Remote)).unwrap(); branches.sort(); assert_eq!(branches, vec![ Branch::remote(BranchName::new("origin/HEAD")), Branch::remote(BranchName::new("origin/dev")), Branch::remote(BranchName::new("origin/master")), ]);
pub fn list_tags(&self) -> Result<Vec<TagName>, GitError>
[src]
List the names of the tags that are contained in the
underlying GitRepository
.
Examples
use radicle_surf::vcs::git::{GitBrowser, GitRepository, TagName}; let repo = GitRepository::new("./data/git-platinum").unwrap(); let mut browser = GitBrowser::new(&repo).unwrap(); let tags = browser.list_tags().unwrap(); // We currently have no tags :( assert_eq!( tags, vec![ TagName::new("v0.1.0"), TagName::new("v0.2.0"), TagName::new("v0.3.0"), TagName::new("v0.4.0"), TagName::new("v0.5.0") ] );
pub fn last_commit(&self, path: &Path) -> Result<Option<Commit>, GitError>
[src]
Given a Path
to a file, return the last Commit
that touched that file.
Examples
use radicle_surf::vcs::git::{GitBrowser, GitRepository, Sha1}; use radicle_surf::file_system::{Label, Path, SystemType}; use radicle_surf::file_system::unsound; use git2; let repo = GitRepository::new("./data/git-platinum") .expect("Could not retrieve ./data/git-test as git repository"); let mut browser = GitBrowser::new(&repo).expect("Could not initialise Browser"); // Clamp the Browser to a particular commit browser.commit(Sha1::new("d6880352fc7fda8f521ae9b7357668b17bb5bad5")).expect("Failed to set commit"); let head_commit = browser.get_history().0.first().clone(); let expected_commit = git2::Oid::from_str("d3464e33d75c75c99bfb90fa2e9d16efc0b7d0e3") .expect("Failed to create Oid"); let readme_last_commit = browser .last_commit(&Path::with_root(&[unsound::label::new("README.md")])) .expect("Failed to get last commit") .map(|commit| commit.id()); assert_eq!(readme_last_commit, Some(expected_commit)); let expected_commit = git2::Oid::from_str("e24124b7538658220b5aaf3b6ef53758f0a106dc") .expect("Failed to create Oid"); let memory_last_commit = browser .last_commit(&Path::with_root(&[unsound::label::new("src"), unsound::label::new("memory.rs")])) .expect("Failed to get last commit") .map(|commit| commit.id()); assert_eq!(memory_last_commit, Some(expected_commit));
use radicle_surf::vcs::git::{GitBrowser, GitRepository, Sha1}; use radicle_surf::file_system::{Label, Path, SystemType}; use radicle_surf::file_system::unsound; let repo = GitRepository::new("./data/git-platinum") .expect("Could not retrieve ./data/git-platinum as git repository"); let mut browser = GitBrowser::new(&repo).expect("Could not initialise Browser"); // Set the browser history to the initial commit browser.commit(Sha1::new("d3464e33d75c75c99bfb90fa2e9d16efc0b7d0e3")).unwrap(); let head_commit = browser.get_history().0.first().clone(); // memory.rs is commited later so it should not exist here. let memory_last_commit = browser .last_commit(&Path::with_root(&[unsound::label::new("src"), unsound::label::new("memory.rs")])) .expect("Failed to get last commit") .map(|commit| commit.id()); assert_eq!(memory_last_commit, None); // README.md exists in this commit. let readme_last_commit = browser .last_commit(&Path::with_root(&[unsound::label::new("README.md")])) .expect("Failed to get last commit") .map(|commit| commit.id()); assert_eq!(readme_last_commit, Some(head_commit.id()));
use radicle_surf::vcs::git::{BranchName, GitBrowser, GitRepository, Sha1}; use radicle_surf::vcs::git::git2::{Oid}; use radicle_surf::file_system::{Label, Path, SystemType}; use radicle_surf::file_system::unsound; let repo = GitRepository::new("./data/git-platinum") .expect("Could not retrieve ./data/git-platinum as git repository"); let mut browser = GitBrowser::new(&repo).expect("Could not initialise Browser"); // Check that last commit is the actual last commit even if head commit differs. browser.commit(Sha1::new("19bec071db6474af89c866a1bd0e4b1ff76e2b97")).unwrap(); let expected_commit_id = Oid::from_str("f3a089488f4cfd1a240a9c01b3fcc4c34a4e97b2").unwrap(); let gitignore_last_commit_id = browser .last_commit(&unsound::path::new("~/examples/Folder.svelte")) .expect("Failed to get last commit") .map(|commit| commit.id()); assert_eq!(gitignore_last_commit_id, Some(expected_commit_id));
use radicle_surf::vcs::git::{BranchName, GitBrowser, GitRepository, Sha1}; use radicle_surf::vcs::git::git2::{Oid}; use radicle_surf::file_system::{Label, Path, SystemType}; use radicle_surf::file_system::unsound; let repo = GitRepository::new("./data/git-platinum") .expect("Could not retrieve ./data/git-platinum as git repository"); let mut browser = GitBrowser::new(&repo).expect("Could not initialise Browser"); // Check that last commit is the actual last commit even if head commit differs. browser.commit(Sha1::new("19bec071db6474af89c866a1bd0e4b1ff76e2b97")).unwrap(); let expected_commit_id = Oid::from_str("2429f097664f9af0c5b7b389ab998b2199ffa977").unwrap(); let gitignore_last_commit_id = browser .last_commit(&unsound::path::new("~/this/is/a/really/deeply/nested/directory/tree")) .expect("Failed to get last commit") .map(|commit| commit.id()); // TODO(fintan): Fix this when we figure out how to get last commit on directory assert_eq!(gitignore_last_commit_id, None);