Skip to content

Commit a7dbed1

Browse files
committed
consolidate naming of directories, use same convention as git2 (#364)
1 parent b94471a commit a7dbed1

File tree

6 files changed

+33
-9
lines changed

6 files changed

+33
-9
lines changed

cargo-smart-release/src/utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ pub fn is_pre_release_version(semver: &Version) -> bool {
5252

5353
pub fn is_top_level_package(manifest_path: &Utf8Path, repo: &git::Repository) -> bool {
5454
manifest_path
55-
.strip_prefix(repo.work_tree().as_ref().expect("repo with working tree"))
55+
.strip_prefix(repo.work_dir().as_ref().expect("repo with working tree"))
5656
.map_or(false, |p| p.components().count() == 1)
5757
}
5858

git-repository/examples/stats.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
55
let repo = git::discover(".")?.apply_environment();
66
println!(
77
"Repo: {}",
8-
repo.work_tree().as_deref().unwrap_or(repo.git_dir()).display()
8+
repo.work_dir().as_deref().unwrap_or(repo.git_dir()).display()
99
);
1010
let commit_ids = repo
1111
.head()?

git-repository/src/reference/iter.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,30 @@ impl<'r> Platform<'r> {
4343
repo: self.repo,
4444
})
4545
}
46+
47+
// TODO: tests
48+
/// Return an iterator over all references that are tags.
49+
///
50+
/// They are all prefixed with `refs/tags`.
51+
pub fn tags(&self) -> Result<Iter<'_>, init::Error> {
52+
Ok(Iter {
53+
inner: self.platform.prefixed("refs/tags/")?,
54+
peel: false,
55+
repo: self.repo,
56+
})
57+
}
58+
59+
// TODO: tests
60+
/// Return an iterator over all branches.
61+
///
62+
/// They are all prefixed with `refs/heads`.
63+
pub fn branches(&self) -> Result<Iter<'_>, init::Error> {
64+
Ok(Iter {
65+
inner: self.platform.prefixed("refs/heads/")?,
66+
peel: false,
67+
repo: self.repo,
68+
})
69+
}
4670
}
4771

4872
impl<'r> Iter<'r> {

git-repository/src/repository/location.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ impl crate::Repository {
55
}
66

77
/// Return the work tree containing all checked out files, if there is one.
8-
pub fn work_tree(&self) -> Option<&std::path::Path> {
8+
pub fn work_dir(&self) -> Option<&std::path::Path> {
99
self.work_tree.as_deref()
1010
}
1111

1212
/// The directory of the binary path of the current process.
13-
pub fn install_directory(&self) -> std::io::Result<std::path::PathBuf> {
13+
pub fn install_dir(&self) -> std::io::Result<std::path::PathBuf> {
1414
std::env::current_exe()
1515
}
1616

git-repository/src/repository/snapshots.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ impl crate::Repository {
5555
.map_err(|e| err.get_or_insert(e.into()))
5656
.ok()
5757
});
58-
match self.work_tree() {
58+
match self.work_dir() {
5959
None => {
6060
// TODO: replace with ref-spec `HEAD:.mailmap` for less verbose way of getting the blob id
6161
blob_id = blob_id.or_else(|| {
@@ -94,7 +94,7 @@ impl crate::Repository {
9494
.value::<git_config::values::Path<'_>>("mailmap", None, "file")
9595
.ok()
9696
.and_then(|path| {
97-
let install_dir = self.install_directory().ok()?;
97+
let install_dir = self.install_dir().ok()?;
9898
match path.interpolate(Some(install_dir.as_path())) {
9999
Ok(path) => Some(path),
100100
Err(e) => {

git-repository/tests/init/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ mod bare {
55
let repo = git_repository::init_bare(tmp.path()).unwrap();
66
assert_eq!(repo.kind(), git_repository::Kind::Bare);
77
assert!(
8-
repo.work_tree().is_none(),
8+
repo.work_dir().is_none(),
99
"a worktree isn't present in bare repositories"
1010
);
1111
assert_eq!(
@@ -34,15 +34,15 @@ mod non_bare {
3434
let tmp = tempfile::tempdir()?;
3535
let repo = git_repository::init(tmp.path())?;
3636
assert_eq!(repo.kind(), git_repository::Kind::WorkTree);
37-
assert_eq!(repo.work_tree(), Some(tmp.path()), "there is a work tree by default");
37+
assert_eq!(repo.work_dir(), Some(tmp.path()), "there is a work tree by default");
3838
assert_eq!(
3939
repo.git_dir(),
4040
tmp.path().join(".git"),
4141
"there is a work tree by default"
4242
);
4343
assert_eq!(git_repository::open(repo.git_dir())?, repo);
4444
assert_eq!(
45-
git_repository::open(repo.work_tree().as_ref().expect("non-bare repo"))?,
45+
git_repository::open(repo.work_dir().as_ref().expect("non-bare repo"))?,
4646
repo
4747
);
4848
Ok(())

0 commit comments

Comments
 (0)