Exemplo n.º 1
0
 def _raise_ref_conflict(scm, ref, new_rev, checkpoint):
     # If this commit is a duplicate of the existing commit at 'ref', return
     # the existing commit. Otherwise, error out and require user to re-run
     # with --force as needed
     orig_rev = scm.get_ref(ref)
     if scm.diff(orig_rev, new_rev):
         if checkpoint:
             raise CheckpointExistsError(ref)
         raise ExperimentExistsError(ref)
     return orig_rev
Exemplo n.º 2
0
Arquivo: base.py Projeto: ivalearn/dvc
    def commit(
        cls,
        scm: "Git",
        exp_hash: str,
        exp_name: Optional[str] = None,
        force: bool = False,
        checkpoint: bool = False,
    ):
        """Commit stages as an experiment and return the commit SHA."""
        rev = scm.get_rev()
        if not scm.is_dirty():
            logger.debug("No changes to commit")
            raise UnchangedExperimentError(rev)

        branch = scm.get_ref(EXEC_BRANCH, follow=False)
        if branch:
            old_ref = rev
            logger.debug("Commit to current experiment branch '%s'", branch)
        else:
            baseline_rev = scm.get_ref(EXEC_BASELINE)
            name = exp_name if exp_name else f"exp-{exp_hash[:5]}"
            ref_info = ExpRefInfo(baseline_rev, name)
            branch = str(ref_info)
            old_ref = None
            if not force and scm.get_ref(branch):
                if checkpoint:
                    raise CheckpointExistsError(ref_info.name)
                raise ExperimentExistsError(ref_info.name)
            logger.debug("Commit to new experiment branch '%s'", branch)

        scm.add([], update=True)
        scm.commit(f"dvc: commit experiment {exp_hash}", no_verify=True)
        new_rev = scm.get_rev()
        scm.set_ref(branch, new_rev, old_ref=old_ref)
        scm.set_ref(EXEC_BRANCH, branch, symbolic=True)
        if checkpoint:
            scm.set_ref(EXEC_CHECKPOINT, new_rev)
        return new_rev
Exemplo n.º 3
0
 def on_diverged(ref: str, checkpoint: bool):
     ref_info = ExpRefInfo.from_ref(ref)
     if checkpoint:
         raise CheckpointExistsError(ref_info.name)
     raise ExperimentExistsError(ref_info.name)