Skip to content

Commit 64a62ff

Browse files
committed
docs(test): Expand 'git' documentation
1 parent 97ccb65 commit 64a62ff

File tree

1 file changed

+18
-13
lines changed
  • crates/cargo-test-support/src

1 file changed

+18
-13
lines changed

crates/cargo-test-support/src/git.rs

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
//! # Git Testing Support
22
//!
33
//! ## 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
55
//! project that you can then use as a dependency. It will automatically add all
66
//! the files you specify in the project and commit them to the repository.
7-
//! Example:
7+
//!
8+
//! ### Example:
89
//!
910
//! ```no_run
1011
//! # use cargo_test_support::project;
@@ -31,7 +32,8 @@
3132
//! ```
3233
//!
3334
//! ## 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
3537
//! adding files to a blank repository and committing them.
3638
//!
3739
//! If you want to then manipulate the repository (such as adding new files or
@@ -44,17 +46,21 @@ use std::path::{Path, PathBuf};
4446
use std::sync::Once;
4547
use url::Url;
4648

49+
/// Manually construct a [`Repository`]
50+
///
51+
/// See also [`new`], [`repo`]
4752
#[must_use]
4853
pub struct RepoBuilder {
4954
repo: git2::Repository,
5055
files: Vec<PathBuf>,
5156
}
5257

58+
/// See [`new`]
5359
pub struct Repository(git2::Repository);
5460

55-
/// Create a `RepoBuilder` to build a new git repository.
61+
/// Create a [`RepoBuilder`] to build a new git repository.
5662
///
57-
/// Call `build()` to finalize and create the repository.
63+
/// Call [`RepoBuilder::build()`] to finalize and create the repository.
5864
pub fn repo(p: &Path) -> RepoBuilder {
5965
RepoBuilder::init(p)
6066
}
@@ -130,7 +136,7 @@ impl Repository {
130136
}
131137
}
132138

133-
/// Initialize a new repository at the given path.
139+
/// *(`git2`)* Initialize a new repository at the given path.
134140
pub fn init(path: &Path) -> git2::Repository {
135141
default_search_path();
136142
let repo = t!(git2::Repository::init(path));
@@ -158,16 +164,15 @@ fn default_repo_cfg(repo: &git2::Repository) {
158164
t!(cfg.set_str("user.name", "Foo Bar"));
159165
}
160166

161-
/// Create a new git repository with a project.
167+
/// Create a new [`Project`] in a git [`Repository`]
162168
pub fn new<F>(name: &str, callback: F) -> Project
163169
where
164170
F: FnOnce(ProjectBuilder) -> ProjectBuilder,
165171
{
166172
new_repo(name, callback).0
167173
}
168174

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`]
171176
pub fn new_repo<F>(name: &str, callback: F) -> (Project, git2::Repository)
172177
where
173178
F: FnOnce(ProjectBuilder) -> ProjectBuilder,
@@ -182,14 +187,14 @@ where
182187
(git_project, repo)
183188
}
184189

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
186191
pub fn add(repo: &git2::Repository) {
187192
let mut index = t!(repo.index());
188193
t!(index.add_all(["*"].iter(), git2::IndexAddOption::DEFAULT, None));
189194
t!(index.write());
190195
}
191196

192-
/// Add a git submodule to the repository.
197+
/// *(`git2`)* Add a git submodule to the repository
193198
pub fn add_submodule<'a>(
194199
repo: &'a git2::Repository,
195200
url: &str,
@@ -207,7 +212,7 @@ pub fn add_submodule<'a>(
207212
s
208213
}
209214

210-
/// Commit changes to the git repository.
215+
/// *(`git2`)* Commit changes to the git repository
211216
pub fn commit(repo: &git2::Repository) -> git2::Oid {
212217
let tree_id = t!(t!(repo.index()).write_tree());
213218
let sig = t!(repo.signature());
@@ -226,7 +231,7 @@ pub fn commit(repo: &git2::Repository) -> git2::Oid {
226231
))
227232
}
228233

229-
/// Create a new tag in the git repository.
234+
/// *(`git2`)* Create a new tag in the git repository
230235
pub fn tag(repo: &git2::Repository, name: &str) {
231236
let head = repo.head().unwrap().target().unwrap();
232237
t!(repo.tag(

0 commit comments

Comments
 (0)