Skip to content

Commit f8294dc

Browse files
author
Stephan Dilly
committed
cleanup some result return types
1 parent 11f78a4 commit f8294dc

File tree

4 files changed

+26
-61
lines changed

4 files changed

+26
-61
lines changed

asyncgit/src/sync/diff.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -313,10 +313,7 @@ mod tests {
313313

314314
assert_eq!(get_statuses(repo_path), (1, 0));
315315

316-
assert_eq!(
317-
stage_add_file(repo_path, file_path).unwrap(),
318-
true
319-
);
316+
stage_add_file(repo_path, file_path).unwrap();
320317

321318
assert_eq!(get_statuses(repo_path), (0, 1));
322319

@@ -378,9 +375,7 @@ mod tests {
378375
assert_eq!(res.len(), 1);
379376
assert_eq!(res[0].path, "bar.txt");
380377

381-
let res =
382-
stage_add_file(repo_path, Path::new("bar.txt")).unwrap();
383-
assert_eq!(res, true);
378+
stage_add_file(repo_path, Path::new("bar.txt")).unwrap();
384379
assert_eq!(get_statuses(repo_path), (0, 1));
385380

386381
// overwrite with next content

asyncgit/src/sync/reset.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ mod tests {
213213
.write_all(b"file3")?;
214214
}
215215

216-
assert!(stage_add_all(repo_path, "*").unwrap());
216+
stage_add_all(repo_path, "*").unwrap();
217217
commit(repo_path, "msg").unwrap();
218218

219219
{
@@ -295,10 +295,7 @@ mod tests {
295295

296296
assert_eq!(get_statuses(repo_path), (1, 0));
297297

298-
assert_eq!(
299-
stage_add_file(repo_path, file_path).unwrap(),
300-
true
301-
);
298+
stage_add_file(repo_path, file_path).unwrap();
302299

303300
assert_eq!(get_statuses(repo_path), (0, 1));
304301

asyncgit/src/sync/utils.rs

Lines changed: 19 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -68,57 +68,45 @@ pub fn commit(repo_path: &str, msg: &str) -> Result<Oid> {
6868
}
6969

7070
/// add a file diff from workingdir to stage (will not add removed files see `stage_addremoved`)
71-
pub fn stage_add_file(repo_path: &str, path: &Path) -> Result<bool> {
71+
pub fn stage_add_file(repo_path: &str, path: &Path) -> Result<()> {
7272
scope_time!("stage_add_file");
7373

7474
let repo = repo(repo_path)?;
7575

7676
let mut index = repo.index()?;
7777

78-
if index.add_path(path).is_ok() {
79-
index.write()?;
80-
return Ok(true);
81-
}
78+
index.add_path(path)?;
79+
index.write()?;
8280

83-
Ok(false)
81+
Ok(())
8482
}
8583

8684
/// like `stage_add_file` but uses a pattern to match/glob multiple files/folders
87-
pub fn stage_add_all(repo_path: &str, pattern: &str) -> Result<bool> {
85+
pub fn stage_add_all(repo_path: &str, pattern: &str) -> Result<()> {
8886
scope_time!("stage_add_all");
8987

9088
let repo = repo(repo_path)?;
9189

9290
let mut index = repo.index()?;
9391

94-
if index
95-
.add_all(vec![pattern], IndexAddOption::DEFAULT, None)
96-
.is_ok()
97-
{
98-
index.write()?;
99-
return Ok(true);
100-
}
92+
index.add_all(vec![pattern], IndexAddOption::DEFAULT, None)?;
93+
index.write()?;
10194

102-
Ok(false)
95+
Ok(())
10396
}
10497

10598
/// stage a removed file
106-
pub fn stage_addremoved(
107-
repo_path: &str,
108-
path: &Path,
109-
) -> Result<bool> {
99+
pub fn stage_addremoved(repo_path: &str, path: &Path) -> Result<()> {
110100
scope_time!("stage_addremoved");
111101

112102
let repo = repo(repo_path)?;
113103

114104
let mut index = repo.index()?;
115105

116-
if index.remove_path(path).is_ok() {
117-
index.write()?;
118-
return Ok(true);
119-
}
106+
index.remove_path(path)?;
107+
index.write()?;
120108

121-
Ok(false)
109+
Ok(())
122110
}
123111

124112
#[cfg(test)]
@@ -148,10 +136,7 @@ mod tests {
148136

149137
assert_eq!(get_statuses(repo_path), (1, 0));
150138

151-
assert_eq!(
152-
stage_add_file(repo_path, file_path).unwrap(),
153-
true
154-
);
139+
stage_add_file(repo_path, file_path).unwrap();
155140

156141
assert_eq!(get_statuses(repo_path), (0, 1));
157142

@@ -176,10 +161,7 @@ mod tests {
176161

177162
assert_eq!(get_statuses(repo_path), (1, 0));
178163

179-
assert_eq!(
180-
stage_add_file(repo_path, file_path).unwrap(),
181-
true
182-
);
164+
stage_add_file(repo_path, file_path).unwrap();
183165

184166
assert_eq!(get_statuses(repo_path), (0, 1));
185167

@@ -196,7 +178,7 @@ mod tests {
196178
let repo_path = root.as_os_str().to_str().unwrap();
197179

198180
assert_eq!(
199-
stage_add_file(repo_path, file_path).unwrap(),
181+
stage_add_file(repo_path, file_path).is_ok(),
200182
false
201183
);
202184
}
@@ -220,10 +202,7 @@ mod tests {
220202

221203
assert_eq!(get_statuses(repo_path), (2, 0));
222204

223-
assert_eq!(
224-
stage_add_file(repo_path, file_path).unwrap(),
225-
true
226-
);
205+
stage_add_file(repo_path, file_path).unwrap();
227206

228207
assert_eq!(get_statuses(repo_path), (1, 1));
229208
}
@@ -248,7 +227,7 @@ mod tests {
248227

249228
assert_eq!(status_count(StatusType::WorkingDir), 3);
250229

251-
assert_eq!(stage_add_all(repo_path, "a/d").unwrap(), true);
230+
stage_add_all(repo_path, "a/d").unwrap();
252231

253232
assert_eq!(status_count(StatusType::WorkingDir), 1);
254233
assert_eq!(status_count(StatusType::Stage), 2);
@@ -274,10 +253,7 @@ mod tests {
274253
.write_all(b"test file1 content")
275254
.unwrap();
276255

277-
assert_eq!(
278-
stage_add_file(repo_path, file_path).unwrap(),
279-
true
280-
);
256+
stage_add_file(repo_path, file_path).unwrap();
281257

282258
commit(repo_path, "commit msg").unwrap();
283259

@@ -287,10 +263,7 @@ mod tests {
287263
// deleted file in diff now
288264
assert_eq!(status_count(StatusType::WorkingDir), 1);
289265

290-
assert_eq!(
291-
stage_addremoved(repo_path, file_path).unwrap(),
292-
true
293-
);
266+
stage_addremoved(repo_path, file_path).unwrap();
294267

295268
assert_eq!(status_count(StatusType::WorkingDir), 0);
296269
assert_eq!(status_count(StatusType::Stage), 1);

src/components/changes.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,10 @@ impl ChangesComponent {
109109
return match status {
110110
StatusItemType::Deleted => {
111111
sync::stage_addremoved(CWD, path)
112-
.unwrap()
112+
.is_ok()
113113
}
114114
_ => sync::stage_add_file(CWD, path)
115-
.unwrap(),
115+
.is_ok(),
116116
};
117117
}
118118
} else {
@@ -121,7 +121,7 @@ impl ChangesComponent {
121121
CWD,
122122
tree_item.info.full_path.as_str(),
123123
)
124-
.unwrap();
124+
.is_ok();
125125
}
126126
} else {
127127
let path =

0 commit comments

Comments
 (0)