File tree Expand file tree Collapse file tree 6 files changed +33
-9
lines changed Expand file tree Collapse file tree 6 files changed +33
-9
lines changed Original file line number Diff line number Diff line change @@ -52,7 +52,7 @@ pub fn is_pre_release_version(semver: &Version) -> bool {
52
52
53
53
pub fn is_top_level_package ( manifest_path : & Utf8Path , repo : & git:: Repository ) -> bool {
54
54
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" ) )
56
56
. map_or ( false , |p| p. components ( ) . count ( ) == 1 )
57
57
}
58
58
Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
5
5
let repo = git:: discover ( "." ) ?. apply_environment ( ) ;
6
6
println ! (
7
7
"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( )
9
9
) ;
10
10
let commit_ids = repo
11
11
. head ( ) ?
Original file line number Diff line number Diff line change @@ -43,6 +43,30 @@ impl<'r> Platform<'r> {
43
43
repo : self . repo ,
44
44
} )
45
45
}
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
+ }
46
70
}
47
71
48
72
impl < ' r > Iter < ' r > {
Original file line number Diff line number Diff line change @@ -5,12 +5,12 @@ impl crate::Repository {
5
5
}
6
6
7
7
/// 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 > {
9
9
self . work_tree . as_deref ( )
10
10
}
11
11
12
12
/// 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 > {
14
14
std:: env:: current_exe ( )
15
15
}
16
16
Original file line number Diff line number Diff line change @@ -55,7 +55,7 @@ impl crate::Repository {
55
55
. map_err ( |e| err. get_or_insert ( e. into ( ) ) )
56
56
. ok ( )
57
57
} ) ;
58
- match self . work_tree ( ) {
58
+ match self . work_dir ( ) {
59
59
None => {
60
60
// TODO: replace with ref-spec `HEAD:.mailmap` for less verbose way of getting the blob id
61
61
blob_id = blob_id. or_else ( || {
@@ -94,7 +94,7 @@ impl crate::Repository {
94
94
. value :: < git_config:: values:: Path < ' _ > > ( "mailmap" , None , "file" )
95
95
. ok ( )
96
96
. and_then ( |path| {
97
- let install_dir = self . install_directory ( ) . ok ( ) ?;
97
+ let install_dir = self . install_dir ( ) . ok ( ) ?;
98
98
match path. interpolate ( Some ( install_dir. as_path ( ) ) ) {
99
99
Ok ( path) => Some ( path) ,
100
100
Err ( e) => {
Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ mod bare {
5
5
let repo = git_repository:: init_bare ( tmp. path ( ) ) . unwrap ( ) ;
6
6
assert_eq ! ( repo. kind( ) , git_repository:: Kind :: Bare ) ;
7
7
assert ! (
8
- repo. work_tree ( ) . is_none( ) ,
8
+ repo. work_dir ( ) . is_none( ) ,
9
9
"a worktree isn't present in bare repositories"
10
10
) ;
11
11
assert_eq ! (
@@ -34,15 +34,15 @@ mod non_bare {
34
34
let tmp = tempfile:: tempdir ( ) ?;
35
35
let repo = git_repository:: init ( tmp. path ( ) ) ?;
36
36
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" ) ;
38
38
assert_eq ! (
39
39
repo. git_dir( ) ,
40
40
tmp. path( ) . join( ".git" ) ,
41
41
"there is a work tree by default"
42
42
) ;
43
43
assert_eq ! ( git_repository:: open( repo. git_dir( ) ) ?, repo) ;
44
44
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" ) ) ?,
46
46
repo
47
47
) ;
48
48
Ok ( ( ) )
You can’t perform that action at this time.
0 commit comments