diff --git a/lib/tfw/components/snapshot_provider.py b/lib/tfw/components/snapshot_provider.py index 8fbf624..8bd17bf 100644 --- a/lib/tfw/components/snapshot_provider.py +++ b/lib/tfw/components/snapshot_provider.py @@ -5,14 +5,14 @@ import re from subprocess import run, CalledProcessError, PIPE from getpass import getuser from os.path import isdir +from os.path import join as joinpath from uuid import uuid4 from dateutil import parser as dateparser -# TODO: gitignore class SnapshotProvider: - def __init__(self, directory, git_dir): + def __init__(self, directory, git_dir, exclude_unix_patterns=None): self._classname = self.__class__.__name__ author = f'{getuser()} via TFW {self._classname}' self.gitenv = { @@ -27,6 +27,8 @@ class SnapshotProvider: self._init_repo() self.__last_valid_branch = self._branch + if exclude_unix_patterns: + self.exclude = exclude_unix_patterns def _init_repo(self): self._check_environment() @@ -105,6 +107,24 @@ class SnapshotProvider: kwargs['env'] = self.gitenv return run(*args, **kwargs) + @property + def exclude(self): + with open(self._exclude_path, 'r') as ofile: + return ofile.read() + + @exclude.setter + def exclude(self, exclude_patterns): + with open(self._exclude_path, 'w') as ifile: + ifile.write('\n'.join(exclude_patterns)) + + @property + def _exclude_path(self): + return joinpath( + self.gitenv['GIT_DIR'], + 'info', + 'exclude' + ) + def take_snapshot(self): if self._head_detached: self._checkout_new_branch_from_head()