Squash and Merge

TensorBay supports squashing and merging between different branches.

Before squash_and_merge(), a dataset client instance with commits on different branches is needed. See more details in Draft and Commit.

../../_images/squash_and_merge.png

Fig. 9 The graphical gas log about the squash and merge operation below.

from tensorbay import GAS

ACCESS_KEY = "Accesskey-*****"
gas = GAS(ACCESS_KEY)
dataset_client = gas.create_dataset("DatasetName")

dataset_client.create_draft("draft-1")
dataset_client.commit("commit-1")

dataset_client.create_branch("dev")
dataset_client.create_draft("draft-2")
dataset_client.commit("commit-2")

dataset_client.create_draft("draft-3")
dataset_client.commit("commit-3")

dataset_client.checkout("main")
dataset_client.create_draft("draft-4")
dataset_client.commit("commit-4")

TensorBay SDK allows squash_and_merge() by giving the target_branch_name:

draft_number = dataset_client.squash_and_merge(
    "draft-5",
    description="description",
    source_branch_name="dev",
    target_branch_name="main",
    strategy="override",
)
dataset_client.checkout(draft_number=draft_number)
dataset_client.commit("commit-5")

Or checkout to the target_branch first. In this case, the current branch is main, so we can do squash_and_merge operation directly.

draft_number = dataset_client.squash_and_merge(
    "draft-5",
    description="description",
    source_branch_name="dev",
    strategy="override",
)
dataset_client.checkout(draft_number=draft_number)
dataset_client.commit("commit-5")

Note

There are three strategies for handling the branch conflict:

  1. “abort”: abort the opetation;

  2. “override”: the squashed branch will override the target branch;

  3. “skip”: keep the origin branch.