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 forinitandstatus, but not for pushing or pulling ("shallow fetch is not supported by the local transport"); usehttps://,ssh://orgit://. TM1 also refuses a local repository its own user doesn't own. deployis 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.deploybrings 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
Commitbefore 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
init | 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. |
uninit | Unties the model from its repository, even with a plan waiting if force. |
status | The tie, and what's on the remote. |
push | 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. |
pull | Plans bringing the model up to branch, one commit or each in turn (mode, None for TM1's SingleCommit); force pulls over local changes. |
deploy | Ties a server not yet tied to a repository, and pulls branch into it, in one step. |
plans | This session's plans not yet executed, each a GitPushPlan or GitPullPlan. |
plan | One of this session's plans, by ID, or None if it has none by that ID (an executed plan is gone). |
execute | Carries 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) -> GitGitInit: 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) -> NoneGitUninit: 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) -> GitGitStatus: 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) -> GitPushPlanGitPush: 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) -> GitPullPlanGitPull: 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) -> NoneGitDeploy: 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 | NoneOne 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) -> Nonetm1.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