Skip to content

Commit

Permalink
Don't delete .git when removing old backups
Browse files Browse the repository at this point in the history
Also save .gitignore
Fix #223
  • Loading branch information
alichtman committed May 11, 2019
1 parent 3847228 commit 9144880
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions shallow_backup/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,18 @@ def safe_mkdir(directory):

def mkdir_overwrite(path):
"""
Makes a new directory, destroying the one at the path if it exits.
Makes a new directory, destroying the contents of the dir at path, if it exits.
Ensures .git and .gitignore files inside of directory are not delected.
"""
if os.path.isdir(path):
rmtree(path)
os.makedirs(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"]
else:
os.makedirs(path)


def mkdir_warn_overwrite(path):
Expand Down

0 comments on commit 9144880

Please sign in to comment.