Skip to content

Commit 724ff2b

Browse files
authored
feat: skip .git when overwriting an existing directory (#485)
* feat: skip `.git` when overwriting an existing directory closes #483 * change file [skip ci]
1 parent 8b80b8a commit 724ff2b

3 files changed

Lines changed: 13 additions & 2 deletions

File tree

.changes/skip-git-directory.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"create-tauri-app": "patch"
3+
"create-tauri-app-js": "patch"
4+
---
5+
6+
Skip deleting `.git` directory when initalizing a project in an already existing directoy.
7+

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[workspace]
2+
resolver = "2"
23
members = ["packages/cli", "packages/cli/node"]
34

45
[profile.release]

packages/cli/src/lib.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,12 +269,15 @@ where
269269
// Remove the target dir contents before rendering the template
270270
// SAFETY: Upon reaching this line, the user already accepted to overwrite
271271
if target_dir.exists() {
272+
#[inline(always)]
272273
fn clean_dir(dir: &std::path::PathBuf) -> anyhow::Result<()> {
273274
for entry in fs::read_dir(dir)?.flatten() {
274275
let path = entry.path();
275276
if entry.file_type()?.is_dir() {
276-
clean_dir(&path)?;
277-
std::fs::remove_dir(path)?;
277+
if entry.file_name() != ".git" {
278+
clean_dir(&path)?;
279+
std::fs::remove_dir(path)?;
280+
}
278281
} else {
279282
fs::remove_file(path)?;
280283
}

0 commit comments

Comments
 (0)