Delete a branch using the git resource

I’m prototyping pipelines to automate the oneflow git branching model. Creating a new git branch and pushing it to github using the concourse git resource works fine using git to create the branch from a particular commit in a task:

git clone develop release
cd release
git checkout -b "$release_branch" "$branch_hash"

and then puting the resource:

- put: release
  params:
      repository: release
      branch: ((.:branch-config.release-branch-name))

At the end of the pipeline, the release branch needs to be deleted. However, I’ve not figured out a way to do this. I’ve tried (in the “release” resource):

cd release
git branch -D "$release_branch"

and then puting the resource:

- put: release
  params:
      repository: release
      branch: "((release-branch))"

The branch deletion works without problem in the shell. The put succeeds but with no effect: there are no new commits or tags. The removal of the release-branch ref is the only change and it does not get reflected back to the original source of the repo (on github).

It may very well be that this is just a limitation of the git resource (after all, the resource is meant to track certain commits)? Or, perhaps branch changes (additions, deletions, …) are reflected only when a commit has been made?

Any ideas? My web searches have not turned up anything. I did find an old project https://github.com/vito/git-branches-resource, but there is no put!
#Support

I’ve never seen this workflow implemented with Concourse. Resources that delete themselves don’t fit cleanly into the current definition of resources. Some resources like the terraform one have had to implement workarounds to allow for deletion and the idea of have a top-level delete step has been discussed in the past.

I don’t fully grok everything the git resource is doing but I would suspect your only option is likely to create your own custom resource for the deletions. I did test if the (scary) method of deleting a branch with git push origin :<branch-name> (note the :) could work but the resource prefixes the branch name with HEAD:refs/heads/ so that doesn’t work.

Thanks for this. Sort of suspected that it would be hard do this with the git resource given its set of configuration and get/put parameters.
While the git resource does a lot of great things, I find its resource model a bit confused. It claims that it "Tracks the commits in a git repository ". But then one can muck around with tags and branches–at least to create them. Now, I’m not asking that this be taken out (ha!), but it is a bit confusing you can manipulate state that, downstream in a pipeline can observed, without creating a new version. And some state manipulations are ok (create) and others not (delete).
Guess I need to get to work on a “repository resource”.

Concourse resources exists to track immutable versions of external things. The intention behind the verbs are:

  • check looks for the latest version
  • get retrieves the contents of the latest version
  • put pushes the locally modified contents as a new version

I think delete is different because rather than pushing a new version it’s removing an existing version. With the git resource it would be totally valid to update the branch to have no content as this is just a new hash with “updated” contents. Also whenever Concourse does a put it immediately does a get to make sure the updated version was updated successfully. This kind of breaks if the put deletes the thing. The terraform resource has a workaround where you configure a get_param that no-ops on the implicit get but in that case you’re still updating the state to have a new version even if you’re deleting the objects terraform managed.