Start tracking changes to path.
(self, path)
| 808 | # File-related methods |
| 809 | |
| 810 | def track_file(self, path): |
| 811 | """Start tracking changes to path.""" |
| 812 | _check_path_is_repo_relative(path) |
| 813 | |
| 814 | gl_st, git_st, is_au = self._status_file(path) |
| 815 | |
| 816 | if gl_st.type == GL_STATUS_TRACKED: |
| 817 | raise ValueError('File {0} is already tracked'.format(path)) |
| 818 | elif gl_st.type == GL_STATUS_IGNORED: |
| 819 | raise ValueError( |
| 820 | 'File {0} is ignored. Edit the .gitignore file to stop ignoring ' |
| 821 | 'file {0}'.format(path)) |
| 822 | |
| 823 | # If we reached this point we know that the file to track is a untracked |
| 824 | # file. This means that in the Git world, the file could be either: |
| 825 | # (i) a new file for Git => add the file; |
| 826 | # (ii) an assumed unchanged file => unmark it. |
| 827 | if git_st == pygit2.GIT_STATUS_WT_NEW: # Case (i) |
| 828 | with self._index as index: |
| 829 | git_path = _get_git_path(path) |
| 830 | index.add(git_path) |
| 831 | elif is_au: # Case (ii) |
| 832 | git('update-index', '--no-assume-unchanged', path, |
| 833 | _cwd=self.gl_repo.root) |
| 834 | else: |
| 835 | raise GlError('File {0} in unknown status {1}'.format(path, git_st)) |
| 836 | |
| 837 | def untrack_file(self, path): |
| 838 | """Stop tracking changes to path.""" |