Skip to content

Commit

Permalink
repository(doc): top-level of 'path' module (#164)
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Sep 13, 2021
1 parent 329d183 commit 066f59b
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions git-repository/src/path/create.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![allow(missing_docs)]
use std::{
fs::{self, OpenOptions},
io::Write,
Expand Down
1 change: 1 addition & 0 deletions git-repository/src/path/discover.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![allow(missing_docs)]
use std::{
borrow::Cow,
path::{Component, Path},
Expand Down
1 change: 1 addition & 0 deletions git-repository/src/path/is_git.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![allow(missing_docs)]
use std::path::{Path, PathBuf};

#[derive(Debug, thiserror::Error)]
Expand Down
6 changes: 4 additions & 2 deletions git-repository/src/path/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![allow(missing_docs)]

use std::path::PathBuf;

pub use is_git::{is_bare, is_git};
Expand All @@ -20,20 +18,24 @@ impl AsRef<std::path::Path> for Path {
}

impl Path {
/// Instantiate a new path from `dir` which is expected to be the `.git` directory, with `kind` indicating
/// whether it's a bare repository or not.
pub fn from_dot_git_dir(dir: impl Into<PathBuf>, kind: Kind) -> Self {
let dir = dir.into();
match kind {
Kind::WorkTree => Path::WorkTree(dir.parent().expect("this is a sub-directory").to_owned()),
Kind::Bare => Path::Repository(dir),
}
}
/// Returns the [kind][Kind] of this repository path.
pub fn kind(&self) -> Kind {
match self {
Path::WorkTree(_) => Kind::WorkTree,
Path::Repository(_) => Kind::Bare,
}
}

/// Consume and split this path into the location of the `.git` directory as well as an optional path to the work tree.
pub fn into_repository_and_work_tree_directories(self) -> (PathBuf, Option<PathBuf>) {
match self {
crate::Path::WorkTree(working_tree) => (working_tree.join(".git"), Some(working_tree)),
Expand Down

0 comments on commit 066f59b

Please sign in to comment.