From e417fe238fa5d791b075162fb7e0a715ee5017d4 Mon Sep 17 00:00:00 2001 From: Aaron Lichtman Date: Tue, 24 Mar 2020 22:58:02 -0500 Subject: [PATCH] Correctly exclude files on reinstallation and add tests --- README.md | 7 +++++-- shallow_backup/utils.py | 4 ++-- tests/test_reinstall_dotfiles.py | 8 ++++++++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 1a6c63eb..5d34c2c2 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ Contents * [What can I back up?](#what-can-i-back-up) * [Backup Customization](#backup-customization) * [Output Structure](#output-structure) - * [Reinstallation](#reinstallation) + * [Reinstalling Dotfiles](#reinstalling-dotfiles) * [Inspiration](#inspiration) * [Want to contribute?](#want-to-contribute) @@ -204,10 +204,13 @@ backup_dir/ └── sublime3_list.txt ``` -### Reinstallation +### Reinstalling Dotfiles To reinstall your dotfiles, clone your dotfiles repo and make sure your shallow-backup config path can be found at either `~/.config/shallow-backup.conf` or `$XDG_CONFIG_HOME/.shallow_backup.conf`. Set the `backup-path` key in the config to the path of your cloned dotfiles. Then run `$ shallow-backup -reinstall_dots`. + +When reinstalling your dotfiles, the top level `.git/`, `.gitignore`, `img/` and `README.md` files / directories are ignored. + ### Inspiration --- diff --git a/shallow_backup/utils.py b/shallow_backup/utils.py index 67dea865..4568c29c 100644 --- a/shallow_backup/utils.py +++ b/shallow_backup/utils.py @@ -139,8 +139,8 @@ def get_abs_path_subfiles(directory): root_git_dir = os.path.join(directory, ".git") root_gitignore = os.path.join(directory, ".gitignore") img = os.path.join(directory, "img") - readme = os.path.join(directory, "readme.md") - if not any(root_git_dir, root_gitignore, img, readme) in joined: + readme = os.path.join(directory, "README.md") + if not any(x in joined for x in [root_git_dir, root_gitignore, img, readme]): file_paths.append(joined) else: print_path_red("Excluded:", joined) diff --git a/tests/test_reinstall_dotfiles.py b/tests/test_reinstall_dotfiles.py index 47e0445e..5967abbc 100644 --- a/tests/test_reinstall_dotfiles.py +++ b/tests/test_reinstall_dotfiles.py @@ -60,6 +60,11 @@ def create_git_dir(parent): git_dir_should_not_reinstall = create_git_dir(DOTFILES_PATH) git_dir_should_reinstall = create_git_dir(testfolder2) + # Dotfiles / folders to not reinstall + img_dir_should_not_reinstall = create_dir(DOTFILES_PATH, "img") + create_file(img_dir_should_not_reinstall, "test.png") + create_file(DOTFILES_PATH, "README.md") + # SAMPLE DOTFILES TO REINSTALL create_file(testfolder2, ".testsubfolder_rc1") create_file(testfolder2, ".gitignore") @@ -86,6 +91,9 @@ def test_reinstall_dotfiles(self): # Don't reinstall root-level git files assert not os.path.isdir(os.path.join(FAKE_HOME_DIR, ".git")) assert not os.path.isfile(os.path.join(FAKE_HOME_DIR, ".gitignore")) + # Don't reinstall img or README.md + assert not os.path.isdir(os.path.join(FAKE_HOME_DIR, "img")) + assert not os.path.isfile(os.path.join(FAKE_HOME_DIR, "README.md")) # Do reinstall all other git files assert os.path.isdir(os.path.join(testfolder2, ".git")) assert os.path.isfile(os.path.join(testfolder2, ".gitignore"))