I'm using API explorer to create a POC for some API development.
Step 2 of this process is to create a new branch based off master, essentially doing this, but through the API:
I'm trying to do that with an sdk call like the following:
response = sdk.create_git_branch(
project_id="my_project_name",
body=mdls.WriteGitBranch(
name="my_new_branch_name",
ref="master"
))
However I've tested this about a dozen times now, and every time the new branch is created using the HEAD of the current branch rather than the master branch.
It'd be fine if there was a way to reset the branch to production after creating it, (similar to the "Pull from Production" action in the UI), but I don't see a way to just reset that branch via the API.
Can anyone help? Just this just not work as documented, or am I doing something wrong?
Works for me if the `ref` value when creating branch needs is commit hash of production branch
import looker_sdk
sdk = looker_sdk.init40()
project_workspace = sdk.project_workspace('your_proj')
prod_ref = project_workspace.git_head
sdk.update_session(body=looker_sdk.models40.WriteApiSession(workspace_id='dev'))
sdk.create_git_branch(
project_id='your_proj',
body=looker_sdk.sdk.api40.models.WriteGitBranch(name='new_branch', ref=prod_ref)
)
Works for me if the `ref` value is the commit hash of production branch
import looker_sdk
sdk = looker_sdk.init40()
project = 'your_proj'
project_workspace = sdk.project_workspace(project)
prod_ref = project_workspace.git_head
sdk.update_session(body=looker_sdk.models40.WriteApiSession(workspace_id='dev'))
sdk.create_git_branch(
project_id=project,
body=looker_sdk.sdk.api40.models.WriteGitBranch(name='test', ref=prod_ref)
)
Although the problem is that if I'm signed in as a user with a very stale branch, it'll fail because it is not aware of the commit ref. So I'd have to pull from production for the branch first.
It would definitely be better if we could just have option to create off of production branch