Skip to content

Commit

Permalink
Don't delete .git, .gitignore or README
Browse files Browse the repository at this point in the history
  • Loading branch information
alichtman committed May 12, 2019
1 parent f5ad9c9 commit 63c62be
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions shallow_backup/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,21 @@ def mkdir_overwrite(path):
Ensures .git and .gitignore files inside of directory are not delected.
"""
if os.path.isdir(path):
for dirpath, dirs, files in os.walk(path):
# Delete files
[os.remove(os.path.join(dirpath, name)) for name in files if name != ".gitignore"]

# Delete directories
[rmtree(os.path.join(dirpath, name)) for name in dirs if name != ".git"]
dirs = []
files = []
for f in os.listdir(path):
full_path = os.path.join(path, f)
# Allow dotfiles to be a sub-repo.
if full_path.endswith(".git") or full_path.endswith(".gitignore") or full_path.endswith("README.md"):
continue

if os.path.isdir(full_path):
dirs.append(full_path)
else:
files.append(full_path)

[os.remove(file) for file in files]
[rmtree(dir) for dir in dirs]
else:
os.makedirs(path)

Expand Down

0 comments on commit 63c62be

Please sign in to comment.