MCPcopy
hub / github.com/treeverse/dvc / commit

Method commit

dvc/repo/experiments/executor/base.py:739–785  ·  view source on GitHub ↗

Commit stages as an experiment and return the commit SHA.

(
        cls,
        scm: "Git",
        exp_hash: str,
        exp_name: Optional[str] = None,
        force: bool = False,
        message: Optional[str] = None,
    )

Source from the content-addressed store, hash-verified

737
738 @classmethod
739 def commit(
740 cls,
741 scm: "Git",
742 exp_hash: str,
743 exp_name: Optional[str] = None,
744 force: bool = False,
745 message: Optional[str] = None,
746 ):
747 """Commit stages as an experiment and return the commit SHA."""
748
749 rev = scm.get_rev()
750 if not scm.is_dirty(untracked_files=False):
751 logger.debug("No changes to commit")
752
753 check_conflict = False
754 branch = scm.get_ref(EXEC_BRANCH, follow=False)
755 if branch:
756 old_ref = rev
757 logger.debug("Commit to current experiment branch '%s'", branch)
758 else:
759 baseline_rev = scm.get_ref(EXEC_BASELINE)
760 name = exp_name or f"exp-{exp_hash[:5]}"
761 ref_info = ExpRefInfo(baseline_rev, name)
762 branch = str(ref_info)
763 old_ref = None
764 if scm.get_ref(branch):
765 if not force:
766 check_conflict = True
767 logger.debug(
768 "%s existing experiment branch '%s'",
769 "Replace" if force else "Reuse",
770 branch,
771 )
772 else:
773 logger.debug("Commit to new experiment branch '%s'", branch)
774
775 scm.add([], update=True)
776 message = message or f"dvc: commit experiment {exp_hash}"
777 scm.commit(message, no_verify=True)
778 new_rev = scm.get_rev()
779 if check_conflict:
780 new_rev = cls._raise_ref_conflict(scm, branch, new_rev)
781 else:
782 scm.set_ref(branch, new_rev, old_ref=old_ref)
783 scm.set_ref(EXEC_BRANCH, branch, symbolic=True)
784
785 return new_rev
786
787 @staticmethod
788 def _raise_ref_conflict(scm, ref, new_rev):

Callers 7

commitFunction · 0.45
commit_2_to_3Function · 0.45
drop_data_indexMethod · 0.45
dataMethod · 0.45
_stash_commit_depsMethod · 0.45
saveMethod · 0.45
_repro_commitMethod · 0.45

Calls 4

ExpRefInfoClass · 0.90
_raise_ref_conflictMethod · 0.80
get_revMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected