skipcheck

TM1 client · Docs · More services

GitService

from skipcheck_tm1.services import GitService

TM1 Git (schema 11.5.0): ties the model to a Git repository, pushes its objects there as JSON files (dimensions/Region.json, …), and pulls them back, on this server or another.

Pushing and pulling are two steps: push and pull make a plan saying what would happen (the files, or the operations, such as Skip Dimensions('Region')), and execute carries it out.

What TM1 (11.8) does here that you might not expect:

  • A plan belongs to the TM1 session that made it: another session can't see it or run it. Executing a plan uses it up; it's gone afterwards.
  • The remote needs a commit on the branch to start from: TM1 can't make a repository's first commit, and pushing when the model hasn't changed is refused too (both "Cannot create bare commit").
  • A local file:// remote works for init and status, but not for pushing or pulling ("shallow fetch is not supported by the local transport"); use https://, ssh:// or git://. TM1 also refuses a local repository its own user doesn't own.
  • deploy is refused while Git is initialized ("Cannot re-deploy"): it's for a server not yet tied to the repository.
  • A pull compares commits, not the model: it plans the changes between the commit last deployed and the branch, so an object deleted on the server since is skipped (Skip Dimensions('Region')), not brought back. deploy brings the whole branch.
  • The first pull after the remote moves on still plans the commit TM1 had; the next pull plans the new one. Check the plan's Commit before executing it.

Tie the model to a repository:

# The remote's branch must already have a commit: TM1 can't make the first one
credentials = GitCredentials.password("tm1-bot", token)
return tm1.git.init("https://git.example.com/finance/model.git", "dev", credentials, False)

Push the model's changes:

# Plan the commit, look at the files it would push, then push them
commit = GitCommitDetails("Add the Region dimension", "Ada Analyst", "ada@example.com")
plan = tm1.git.push("main", None, commit, credentials, False)
if plan.source_files:
    tm1.git.execute(plan)

Pull a branch, once the plan is for the commit wanted:

# TM1 11.8 plans the commit it had on the first pull after the remote moves on:
# pull again until the plan is for the commit wanted, then carry it out
for _ in range(3):
    plan = tm1.git.pull("main", credentials, None, False)
    if plan.commit is not None and plan.commit.id and newest.startswith(plan.commit.id):
        tm1.git.execute(plan)
        break

The asyncio flavor, skipcheck_tm1.aio, has the same methods to await, on AsyncGitService.

Members

initTies the model to the repository at url, as deployment deployment (such as dev) if given; force replaces an existing tie; config is a GitConfigurationPatch, or None for TM1's.
uninitUnties the model from its repository, even with a plan waiting if force.
statusThe tie, and what's on the remote.
pushPlans a commit of the model's changes on top of branch (which must exist on the remote), pushed to new_branch or branch; force pushes even if the remote moved on.
pullPlans bringing the model up to branch, one commit or each in turn (mode, None for TM1's SingleCommit); force pulls over local changes.
deployTies a server not yet tied to a repository, and pulls branch into it, in one step.
plansThis session's plans not yet executed, each a GitPushPlan or GitPullPlan.
planOne of this session's plans, by ID, or None if it has none by that ID (an executed plan is gone).
executeCarries out a plan (from push, pull or plans), pushing its files or pulling its operations.

init

init(url: str, deployment: str | None, credentials: GitCredentials, force: bool, config: Any = None) -> Git

GitInit: ties the model to the repository at url, as deployment deployment (such as dev) if given; force replaces an existing tie; config is a GitConfigurationPatch, or None for TM1's. Returns the tie: URL, deployment, deployed commit, and the remote's branches and tags.

TM1 REST ActionImport GitInit

uninit

uninit(force: bool) -> None

GitUninit: unties the model from its repository, even with a plan waiting if force. The model is left as it is.

TM1 REST ActionImport GitUninit

status

status(credentials: GitCredentials) -> Git

GitStatus: the tie, and what's on the remote. A Tm1BadRequestError if Git isn't initialized.

TM1 REST ActionImport GitStatus

push

push(branch: str, new_branch: str | None, commit: GitCommitDetails, credentials: GitCredentials, force: bool) -> GitPushPlan

GitPush: plans a commit of the model's changes on top of branch (which must exist on the remote), pushed to new_branch or branch; force pushes even if the remote moved on. The plan lists the files; execute pushes them.

TM1 REST ActionImport GitPush

pull

pull(branch: str, credentials: GitCredentials, mode: GitPlanExecutionMode | None, force: bool) -> GitPullPlan

GitPull: plans bringing the model up to branch, one commit or each in turn (mode, None for TM1's SingleCommit); force pulls over local changes. Pull again if the plan's Commit isn't the branch's newest: TM1 (11.8) lags a pull behind the remote. The plan lists the operations; execute carries them out.

TM1 REST ActionImport GitPull

deploy

deploy(url: str, branch: str, deployment: str | None, credentials: GitCredentials, force: bool, config: Any = None) -> None

GitDeploy: ties a server not yet tied to a repository, and pulls branch into it, in one step. Refused while Git is initialized. status then shows the commit.

TM1 REST ActionImport GitDeploy

plans

plans(query: ODataQuery | None = None, **options: Any) -> list[GitPlan]

GET GitPlans: this session's plans not yet executed, each a GitPushPlan or GitPullPlan. A Tm1BadRequestError if Git isn't initialized.

TM1 REST EntitySet GitPlans

plan

plan(id: str) -> GitPlan | None

One of this session's plans, by ID, or None if it has none by that ID (an executed plan is gone). TM1 (11.8) sends no @odata.type for GitPlans('id'), so it couldn't be told apart as a push or a pull; the list says, so the plan is found there.

TM1 REST EntitySet GitPlans

execute

execute(plan: GitPlan) -> None

tm1.Execute: carries out a plan (from push, pull or plans), pushing its files or pulling its operations. The plan is used up.

TM1 REST Action GitPushPlan/Execute Action GitPullPlan/Execute