Submit Type With Prolog

Submit Type With Prolog

1. The Submit Type

2. Fast Forward Only

3. Merge If Necessary

4. The Problem

5. The Solution

6. DEMO

7. Possible Further Development

The Submit Type

The Submit Type

The submit type is the strategy that is used on submit
to integrate the change into the destination branch.

Supported Submit Types:

  • Fast Forward Only
  • Merge If Necessary
  • Merge Always
  • Cherry Pick
  • Rebase If Necessary (only from Gerrit 2.6)

Fast Forward Only

Fast Forward Only - Case 1

Sunday-Submit-Type-With-Prolog__1.png

Fast Forward Only - Case 1

Sunday-Submit-Type-With-Prolog__2.png

Fast Forward Only - Case 2

Sunday-Submit-Type-With-Prolog__3.png

Fast Forward Only

Advantages

  • if every change is verified,
    the main build can never break
  • linear history

Fast Forward Only is a good choice for
     stable release branches

Disadvantages

  • whenever a change gets submitted,
    all open changes have to be rebased

Fast Forward Only doesn’t work well for
     development branches with parallel development
     and a high frequency of changes

Merge If Necessary

Merge If Necessary - Case 1

Sunday-Submit-Type-With-Prolog__4.png

Merge If Necessary - Case 1

Sunday-Submit-Type-With-Prolog__5.png

Merge If Necessary - Case 2

Sunday-Submit-Type-With-Prolog__6.png

Merge If Necessary - Case 2

Sunday-Submit-Type-With-Prolog__7.png

Merge If Necessary

Advantages

  • if possible conflicts are automatically resolved
  • no manual rebase/merge is needed

Merge If Necessary is a good choice for
     development branches

Disadvantages

  • the merge commits are not verified,
    the main build may get broken
  • non-linear history

Merge If Necessary is bad for stable release
     branches where stability of the build is important

The Problem

We want to use

  • Fast Forward Only for stable release branches and
  • Merge If Necessary for development branches
Warning Submit Type is a project global setting!

Submit Type

The Problem

Some companies have policies for release branches
that must be globally enforced.

Tip It should be possible to define a final submit type
for release branches on a parent project.

The Solution

Enable controlling the submit type from Prolog.

Tip For each change invoke the submit_type predicate
to compute the submit type for the change.
Tip Implement a submit_type_filter to enforce a
submit type for child projects.
Warning NOT contained in Gerrit 2.5,
comes with Gerrit 2.6

The Solution

Q: Why should this be done in Prolog?

DEMO

Example 1

rules.pl
submit_type(fast_forward_only) :-
  gerrit:change_branch(B), regex_matches('refs/heads/stable.*', B), !.

submit_type(T) :- gerrit:project_default_submit_type(T).

Example 2

rules.pl
submit_type(fast_forward_only) :-
  gerrit:commit_delta('(?<!\.txt)$'),
  gerrit:change_branch(B), regex_matches('refs/heads/stable.*', B), !.
submit_type(T) :- gerrit:project_default_submit_type(T).

Possible Further Development

THE END