Skip to content

Commit 0fef2f4

Browse files
committed
Auto merge of #4364 - Turbo87:git-docs, r=locks
Repository: Add doc comments as the title says... 😅
2 parents 783e10f + a8d5bca commit 0fef2f4

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

src/git.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,25 @@ impl RepositoryConfig {
137137
}
138138

139139
pub struct Repository {
140+
/// bla
140141
pub checkout_path: TempDir,
141142
repository: git2::Repository,
142143
pub credentials: Credentials,
143144
}
144145

145146
impl Repository {
147+
/// Clones the crate index from a remote git server and returns a
148+
/// `Repository` struct to interact with the local copy of the crate index.
149+
///
150+
/// Note that the `user` configuration for the repository is automatically
151+
/// set to `bors <[email protected]>`.
152+
///
153+
/// # Errors
154+
///
155+
/// - If creation of a temporary folder for cloning the crate index fails.
156+
/// - If cloning the crate index fails.
157+
/// - If reading the global git config fails.
158+
///
146159
pub fn open(repository_config: &RepositoryConfig) -> Result<Self, PerformError> {
147160
let checkout_path = tempfile::Builder::new().prefix("git").tempdir()?;
148161

@@ -174,12 +187,21 @@ impl Repository {
174187
})
175188
}
176189

190+
/// Returns the absolute path to the crate index file that corresponds to
191+
/// the given crate name.
192+
///
193+
/// This is similar to [Self::relative_index_file], but returns the absolute
194+
/// path.
177195
pub fn index_file(&self, name: &str) -> PathBuf {
178196
self.checkout_path
179197
.path()
180198
.join(Self::relative_index_file(name))
181199
}
182200

201+
/// Returns the relative path to the crate index file that corresponds to
202+
/// the given crate name.
203+
///
204+
/// see <https://doc.rust-lang.org/cargo/reference/registries.html#index-format>
183205
pub fn relative_index_file(name: &str) -> PathBuf {
184206
let name = name.to_lowercase();
185207
match name.len() {
@@ -190,10 +212,22 @@ impl Repository {
190212
}
191213
}
192214

215+
/// Returns the [Object ID](git2::Oid) of the currently checked out commit
216+
/// in the local crate index repository.
217+
///
218+
/// # Errors
219+
///
220+
/// - If the `HEAD` pointer can't be retrieved.
221+
///
193222
pub fn head_oid(&self) -> Result<git2::Oid, PerformError> {
194223
Ok(self.repository.head()?.target().unwrap())
195224
}
196225

226+
/// Commits the specified file with the specified commit message and pushes
227+
/// the commit to the `master` branch on the `origin` remote.
228+
///
229+
/// Note that `modified_file` expects a file path **relative** to the
230+
/// repository working folder!
197231
fn perform_commit_and_push(&self, msg: &str, modified_file: &Path) -> Result<(), PerformError> {
198232
// git add $file
199233
let mut index = self.repository.index()?;
@@ -241,6 +275,13 @@ impl Repository {
241275
ref_status
242276
}
243277

278+
/// Commits the specified file with the specified commit message and pushes
279+
/// the commit to the `master` branch on the `origin` remote.
280+
///
281+
/// Note that `modified_file` expects an **absolute** file path!
282+
///
283+
/// This function also prints the commit message and a success or failure
284+
/// message to the console.
244285
pub fn commit_and_push(&self, message: &str, modified_file: &Path) -> Result<(), PerformError> {
245286
println!("Committing and pushing \"{}\"", message);
246287

@@ -253,6 +294,8 @@ impl Repository {
253294
})
254295
}
255296

297+
/// Fetches any changes from the `origin` remote and performs a hard reset
298+
/// to the tip of the `origin/master` branch.
256299
pub fn reset_head(&self) -> Result<(), PerformError> {
257300
let mut origin = self.repository.find_remote("origin")?;
258301
let original_head = self.head_oid()?;

0 commit comments

Comments
 (0)