Skip to content

Commit 2584e85

Browse files
committed
fix refresh clone or update
1 parent ccbd9f0 commit 2584e85

File tree

1 file changed

+14
-20
lines changed

1 file changed

+14
-20
lines changed

tmc-langs-util/src/task_executor/course_refresher.rs

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,13 @@ impl CourseRefresher {
8787
let new_clone_path = new_cache_path.join("clone");
8888
log::info!("updating repository to {}", new_clone_path.display());
8989
let old_clone_path = course_cache_path.join("clone");
90-
update_or_clone_repository(&new_clone_path, &old_clone_path, &source_url, &git_branch)?;
90+
update_or_clone_repository(
91+
&new_cache_path,
92+
&new_clone_path,
93+
&old_clone_path,
94+
&source_url,
95+
&git_branch,
96+
)?;
9197
check_directory_names(&new_clone_path)?;
9298
self.progress_reporter
9399
.finish_step("Updated repository".to_string(), None)?;
@@ -188,6 +194,7 @@ pub fn refresh_course(
188194
/// If not found or found but one of the git commands causes an error, deletes course_clone_path and clones course_git_branch from course_source_url there.
189195
/// NOP during testing.
190196
fn update_or_clone_repository(
197+
new_course_root: &Path,
191198
new_clone_path: &Path,
192199
old_clone_path: &Path,
193200
course_source_url: &str,
@@ -198,7 +205,7 @@ fn update_or_clone_repository(
198205

199206
// closure to collect any error that occurs during the process
200207
let copy_and_update_repository = || -> Result<(), UtilError> {
201-
file_util::copy(old_clone_path, new_clone_path)?;
208+
file_util::copy(old_clone_path, new_course_root)?;
202209

203210
let run_git = |args: &[&str]| {
204211
TmcCommand::new("git".to_string())
@@ -211,24 +218,11 @@ fn update_or_clone_repository(
211218
.output_checked()
212219
};
213220

214-
let clone_path_str = new_clone_path.to_str().unwrap();
215-
run_git(&[
216-
"-C",
217-
clone_path_str,
218-
"remote",
219-
"set-url",
220-
"origin",
221-
course_source_url,
222-
])?;
223-
run_git(&["-C", clone_path_str, "fetch", "origin"])?;
224-
run_git(&[
225-
"-C",
226-
clone_path_str,
227-
"checkout",
228-
&format!("origin/{}", course_git_branch),
229-
])?;
230-
run_git(&["-C", clone_path_str, "clean", "-df"])?;
231-
run_git(&["-C", clone_path_str, "checkout", "."])?;
221+
run_git(&["remote", "set-url", "origin", course_source_url])?;
222+
run_git(&["fetch", "origin"])?;
223+
run_git(&["checkout", &format!("origin/{}", course_git_branch)])?;
224+
run_git(&["clean", "-df"])?;
225+
run_git(&["checkout", "."])?;
232226
Ok(())
233227
};
234228
match copy_and_update_repository() {

0 commit comments

Comments
 (0)