Skip to content

Commit

Permalink
Ensure commit is descendant of bootstrap.
Browse files Browse the repository at this point in the history
  • Loading branch information
dainnilsson committed Nov 8, 2023
1 parent 0d6d63b commit 52ba50f
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion gitbark/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from .util import branch_name
from .util import cmd, branch_name
from .git import Commit, BARK_CONFIG
from .project import Cache, Project
from .rule import RuleViolation, CommitRule, AllCommitRule, BranchRule
Expand Down Expand Up @@ -66,12 +66,30 @@ def validate_rules(commit: Commit, project: Project) -> None:
raise RuleViolation(f"invalid commit rules: {e}")


def is_descendant(prev: Commit, new: Commit) -> bool:
"""Checks that the current tip is a descendant of the old tip"""

_, exit_status = cmd(
"git",
"merge-base",
"--is-ancestor",
prev.hash.hex(),
new.hash.hex(),
check=False,
)

return exit_status == 0


def validate_commit(
commit: Commit,
bootstrap: Commit,
project: Project,
on_valid: Callable[[Commit], None],
) -> None:
if not is_descendant(bootstrap, commit):
raise RuleViolation(f"Bootstrap '{bootstrap.hash.hex()}' is not an ancestor")

cache = project.cache

# Re-validate if previously invalid
Expand Down

0 comments on commit 52ba50f

Please sign in to comment.