Explorer

core.check-event-branch

description
Branch rules of a project commit: only the creator of a branch can commit to it, and the parent is the latest commit of the branch. A new branch starts from a commit of the project, and the first branch of a project is main without a parent. See docs/branch.md
type
Fn(commit: @core.project-commit, state: @core.event-check-state) -> List<@core.event-rejection>
expression
fn(commit$0, state$1) =>
  match $1.branch_latest_commit_hash {
    #some(latest$2) =>
      @core.list-concat(
        left: match $1.is_branch_creator {
          true =>
            [],
          false =>
            [#not_branch_creator<@core.event-rejection>]
        },
        right: match @core.option-string-same(a: $0.parent_commit_hash, b: $1.branch_latest_commit_hash) {
          true =>
            [],
          false =>
            [#parent_commit_mismatch<@core.event-rejection>]
        }
      ),
    #none(_) =>
      match $1.project_has_commits {
        true =>
          match $1.parent_in_project {
            true =>
              [],
            false =>
              [#parent_commit_mismatch<@core.event-rejection>]
          },
        false =>
          @core.list-concat(
            left: match @core.equal(left: $0.branch, right: "main") {
              true =>
                [],
              false =>
                [#first_branch_must_be_main<@core.event-rejection>]
            },
            right: match match $0.parent_commit_hash {
                #none(_) =>
                  true,
                #some(p$9) =>
                  false
              } {
              true =>
                [],
              false =>
                [#parent_commit_mismatch<@core.event-rejection>]
            }
          )
      }
  }
visibility
public
core.check-event-branch (project definy, branch compiled-tests, snapshot i6TqClmqVS9FK8rKOvJ43l6Tevx8pvYJ5-zaQqNwemc)
id: GcA0De0WrJZy13txpcjKhOHGInKswySnazN9JUzlcs4
content hash: mkjr7Tf1h0VJjzd9tILl38NB2C2SarKv5xn6Q_R0ojw