From 4601c8771040226f1c6a776143f519fee4b4b1b2 Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Sat, 7 Oct 2023 10:17:04 -0700 Subject: [PATCH] working_copy: move creation of parent dirs to one place I'm about to add handling of parent dirs that are existing ignored files, so it's better to have it in one place. The only functional difference should be that we now create parent directories for git submodules. I don't think that matters. --- lib/src/local_working_copy.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/src/local_working_copy.rs b/lib/src/local_working_copy.rs index d1a05b1d2..415d8910f 100644 --- a/lib/src/local_working_copy.rs +++ b/lib/src/local_working_copy.rs @@ -1076,7 +1076,6 @@ impl TreeState { id: &FileId, executable: bool, ) -> Result { - create_parent_dirs(&self.working_copy_path, path)?; let mut file = OpenOptions::new() .write(true) .create_new(true) // Don't overwrite un-ignored file. Don't follow symlink. @@ -1109,7 +1108,6 @@ impl TreeState { path: &RepoPath, id: &SymlinkId, ) -> Result { - create_parent_dirs(&self.working_copy_path, path)?; let target = self.store.read_symlink(path, id)?; #[cfg(windows)] { @@ -1139,7 +1137,6 @@ impl TreeState { path: &RepoPath, conflict: &Merge>, ) -> Result { - create_parent_dirs(&self.working_copy_path, path)?; let mut file = OpenOptions::new() .write(true) .create_new(true) // Don't overwrite un-ignored file. Don't follow symlink. @@ -1238,6 +1235,9 @@ impl TreeState { if before.is_present() { fs::remove_file(&disk_path).ok(); } + if after.is_present() { + create_parent_dirs(&self.working_copy_path, &path)?; + } // TODO: Check that the file has not changed before overwriting/removing it. match after.into_resolved() { Ok(None) => {