Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly exclude files on reinstallation and add tests #255

Merged
merged 1 commit into from
Mar 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
---

Expand Down
4 changes: 2 additions & 2 deletions shallow_backup/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions tests/test_reinstall_dotfiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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"))