1
1
//! # Git Testing Support
2
2
//!
3
3
//! ## Creating a git dependency
4
- //! `git:: new()` is an easy way to create a new git repository containing a
4
+ //! [` new()`] is an easy way to create a new git repository containing a
5
5
//! project that you can then use as a dependency. It will automatically add all
6
6
//! the files you specify in the project and commit them to the repository.
7
- //! Example:
7
+ //!
8
+ //! ### Example:
8
9
//!
9
10
//! ```no_run
10
11
//! # use cargo_test_support::project;
31
32
//! ```
32
33
//!
33
34
//! ## Manually creating repositories
34
- //! `git::repo()` can be used to create a `RepoBuilder` which provides a way of
35
+ //!
36
+ //! [`repo()`] can be used to create a [`RepoBuilder`] which provides a way of
35
37
//! adding files to a blank repository and committing them.
36
38
//!
37
39
//! If you want to then manipulate the repository (such as adding new files or
@@ -44,17 +46,21 @@ use std::path::{Path, PathBuf};
44
46
use std:: sync:: Once ;
45
47
use url:: Url ;
46
48
49
+ /// Manually construct a [`Repository`]
50
+ ///
51
+ /// See also [`new`], [`repo`]
47
52
#[ must_use]
48
53
pub struct RepoBuilder {
49
54
repo : git2:: Repository ,
50
55
files : Vec < PathBuf > ,
51
56
}
52
57
58
+ /// See [`new`]
53
59
pub struct Repository ( git2:: Repository ) ;
54
60
55
- /// Create a `RepoBuilder` to build a new git repository.
61
+ /// Create a [ `RepoBuilder`] to build a new git repository.
56
62
///
57
- /// Call ` build()` to finalize and create the repository.
63
+ /// Call [`RepoBuilder:: build()`] to finalize and create the repository.
58
64
pub fn repo ( p : & Path ) -> RepoBuilder {
59
65
RepoBuilder :: init ( p)
60
66
}
@@ -130,7 +136,7 @@ impl Repository {
130
136
}
131
137
}
132
138
133
- /// Initialize a new repository at the given path.
139
+ /// *(`git2`)* Initialize a new repository at the given path.
134
140
pub fn init ( path : & Path ) -> git2:: Repository {
135
141
default_search_path ( ) ;
136
142
let repo = t ! ( git2:: Repository :: init( path) ) ;
@@ -158,16 +164,15 @@ fn default_repo_cfg(repo: &git2::Repository) {
158
164
t ! ( cfg. set_str( "user.name" , "Foo Bar" ) ) ;
159
165
}
160
166
161
- /// Create a new git repository with a project.
167
+ /// Create a new [`Project`] in a git [`Repository`]
162
168
pub fn new < F > ( name : & str , callback : F ) -> Project
163
169
where
164
170
F : FnOnce ( ProjectBuilder ) -> ProjectBuilder ,
165
171
{
166
172
new_repo ( name, callback) . 0
167
173
}
168
174
169
- /// Create a new git repository with a project.
170
- /// Returns both the Project and the git Repository.
175
+ /// Create a new [`Project`] with access to the [`Repository`]
171
176
pub fn new_repo < F > ( name : & str , callback : F ) -> ( Project , git2:: Repository )
172
177
where
173
178
F : FnOnce ( ProjectBuilder ) -> ProjectBuilder ,
@@ -182,14 +187,14 @@ where
182
187
( git_project, repo)
183
188
}
184
189
185
- /// Add all files in the working directory to the git index.
190
+ /// *(`git2`)* Add all files in the working directory to the git index
186
191
pub fn add ( repo : & git2:: Repository ) {
187
192
let mut index = t ! ( repo. index( ) ) ;
188
193
t ! ( index. add_all( [ "*" ] . iter( ) , git2:: IndexAddOption :: DEFAULT , None ) ) ;
189
194
t ! ( index. write( ) ) ;
190
195
}
191
196
192
- /// Add a git submodule to the repository.
197
+ /// *(`git2`)* Add a git submodule to the repository
193
198
pub fn add_submodule < ' a > (
194
199
repo : & ' a git2:: Repository ,
195
200
url : & str ,
@@ -207,7 +212,7 @@ pub fn add_submodule<'a>(
207
212
s
208
213
}
209
214
210
- /// Commit changes to the git repository.
215
+ /// *(`git2`)* Commit changes to the git repository
211
216
pub fn commit ( repo : & git2:: Repository ) -> git2:: Oid {
212
217
let tree_id = t ! ( t!( repo. index( ) ) . write_tree( ) ) ;
213
218
let sig = t ! ( repo. signature( ) ) ;
@@ -226,7 +231,7 @@ pub fn commit(repo: &git2::Repository) -> git2::Oid {
226
231
) )
227
232
}
228
233
229
- /// Create a new tag in the git repository.
234
+ /// *(`git2`)* Create a new tag in the git repository
230
235
pub fn tag ( repo : & git2:: Repository , name : & str ) {
231
236
let head = repo. head ( ) . unwrap ( ) . target ( ) . unwrap ( ) ;
232
237
t ! ( repo. tag(
0 commit comments