Example #1
0
    def snapshot(self, message='', user=''):
        """Takes a snapshot of the the current status of the directory"""
        # Recursively build tree structure
        with utils.temp_wd(self.root_dir):
            top_hash = self._create_tree_node('.')

        # Get hash of the current snapshot and if it is detached
        old_hash, detached = self._current_snapshot_hash()

        # Check if any changes were made and if the snapshot should be saved
        if old_hash == top_hash:
            raise CleanDirectoryException('No changes to repository')

        if detached:
            raise DetachedHeadException(
                'Detached HEAD. Snapshot was not saved. '
                'Save as branch to make changes.'
            )

        # Save updated hashcache
        self._save_objhashcache()

        # Update current branch head with new snapshot hash
        self._update_branch_head(top_hash)

        # Insert snapshot data into the snapshot database
        self._insert_snapshot(top_hash, message, user)
        return top_hash
Example #2
0
    def _check_dirty(self):
        """Raises exception if the directory has changes since last save

        Raises:
          DirtyDirectoryException: If changes made since last save
        """
        # Get hash of directory in it's current form
        with utils.temp_wd(self.root_dir):
            dir_hash = self._get_tree_hash('.')

        # Check if any outstanding changes are in the directory
        cur_hash, _ = self._current_snapshot_hash()
        if cur_hash != dir_hash:
            # Changes have been made and we want to warn the user
            raise DirtyDirectoryException(
                'Changes have been made to the directory. '
                'Use force option to overwrite.'
            )