skipcheck

TM1 client · Docs · More services

GitService

using Skipcheck.Tm1.Client.Services;

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: PushAsync and PullAsync make a plan saying what would happen (the files, or the operations, such as Skip Dimensions('Region')), and ExecuteAsync 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 InitAsync and StatusAsync, 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.
  • DeployAsync 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. DeployAsync 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
var credentials = GitCredentials.Password("tm1-bot", token);
return await tm1.Git.InitAsync("https://git.example.com/finance/model.git", "dev", credentials, false, null);

Push the model's changes:

// Plan the commit, look at the files it would push, then push them
var commit = new GitCommitDetails("Add the Region dimension", "Ada Analyst", "ada@example.com");
var plan = await tm1.Git.PushAsync("main", null, commit, credentials, false);
if (plan.SourceFiles is { Count: > 0 })
{
    await tm1.Git.ExecuteAsync(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 (var attempt = 0; attempt < 3; attempt++)
{
    var plan = await tm1.Git.PullAsync("main", credentials, null, false);
    if (plan.Commit?.Id is { } id && newest.StartsWith(id, StringComparison.Ordinal))
    {
        await tm1.Git.ExecuteAsync(plan);
        return;
    }
}

Members

GitService constructorA service that sends its requests through session.
InitAsyncTies the model to the repository at url, as the deployment deployment (such as dev, or null for none), replacing an existing tie if force, with config or, if null, TM1's Git configuration.
UninitAsyncUnties the model from its repository, even with a plan waiting if force.
StatusAsyncThe tie, and what's on the remote.
PushAsyncPlans a commit of the model's changes on top of branch, which must exist on the remote, pushed to newBranch or, if null, to branch; even if the remote moved on if force.
PullAsyncPlans bringing the model up to branch, one commit or each commit in turn (mode, or null for TM1's SingleCommit), over local changes if force.
DeployAsyncTies a server not yet tied to a repository, and pulls branch into it, in one step.
PlansAsyncGET GitPlans, streamed.
PlanAsyncOne of this session's plans, by ID, or null if this session has none by that ID (an executed plan is gone).
ExecuteAsyncCarries out a plan, from PushAsync, PullAsync or PlansAsync, pushing its files or pulling its operations.

GitService

constructor
GitService(Tm1Session session)

A service that sends its requests through session.

InitAsync

Task<Git> InitAsync( string url, string? deployment, GitCredentials credentials, bool force, GitConfigurationPatch? config, CancellationToken cancellationToken = default )

GitInit: ties the model to the repository at url, as the deployment deployment (such as dev, or null for none), replacing an existing tie if force, with config or, if null, TM1's Git configuration. Returns the tie: URL, deployment, deployed commit, and the remote's branches and tags.

TM1 REST ActionImport GitInit

UninitAsync

Task UninitAsync(bool force, CancellationToken cancellationToken = default)

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

StatusAsync

Task<Git> StatusAsync(GitCredentials credentials, CancellationToken cancellationToken = default)

GitStatus: the tie, and what's on the remote. Fails with a Tm1BadRequestException if Git isn't initialized.

TM1 REST ActionImport GitStatus

PushAsync

Task<GitPushPlan> PushAsync( string branch, string? newBranch, GitCommitDetails commit, GitCredentials credentials, bool force, CancellationToken cancellationToken = default )

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

TM1 REST ActionImport GitPush

PullAsync

Task<GitPullPlan> PullAsync( string branch, GitCredentials credentials, GitPlanExecutionMode? mode, bool force, CancellationToken cancellationToken = default )

GitPull: plans bringing the model up to branch, one commit or each commit in turn (mode, or null for TM1's SingleCommit), over local changes if force. 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; ExecuteAsync carries them out.

TM1 REST ActionImport GitPull

DeployAsync

Task DeployAsync( string url, string branch, string? deployment, GitCredentials credentials, bool force, GitConfigurationPatch? config, CancellationToken cancellationToken = default )

GitDeploy: ties a server not yet tied to a repository, and pulls branch into it, in one step. Refused while Git is initialized. Completes when it's deployed; StatusAsync then shows the commit.

TM1 REST ActionImport GitDeploy

PlansAsync

IAsyncEnumerable<GitPlan> PlansAsync(ODataQuery? query = null, CancellationToken cancellationToken = default)

GET GitPlans, streamed: this session's plans not yet executed, each a GitPushPlan or GitPullPlan. Fails with a Tm1BadRequestException if Git isn't initialized.

TM1 REST EntitySet GitPlans

PlanAsync

Task<GitPlan?> PlanAsync(string id, CancellationToken cancellationToken = default)

One of this session's plans, by ID, or null if this session 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

ExecuteAsync

Task ExecuteAsync(GitPlan plan, CancellationToken cancellationToken = default)

tm1.Execute: carries out a plan, from PushAsync, PullAsync or PlansAsync, pushing its files or pulling its operations. The plan is used up.

Throws

ArgumentException
It's not a push or pull plan.

TM1 REST Action GitPushPlan/Execute Action GitPullPlan/Execute