0
votes

I would like to abandon a pull request in TFS using REST API from PowerShell. Besides, I need the source branch to be deleted, too. According to the official docs, it is possible and the sample REST request might look like this:

The URL is:

http://tfs.server/tfs/DefaultCollection/_apis/git/repositories/{repo_ID}/pullrequests/{PR_ID}?api-version=3.0-preview

The body is:

{
  "status": "abandoned",
  "completionOptions": {
    "deleteSourceBranch": "true"
  }  
}

The pull request becomes abandoned as expected, however the source branch is NOT deleted.

Is it possible to delete the source branch when PR is abandoned via REST API? Is so, how? Perhaps, completionOptions is only for completing PR, not abandoning?..

I'm using TFS 2015 Update-3 (version 14.102.25423.0).

1

1 Answers

1
votes

Although the documentation is not clear on this point, it does appear that completionOptions is ignored unless you actually are completing the PR. (What would it do with options that affect the merge commit, since none is created? Also note that git itself resists requests to delete a branch that hasn't been merged...)

It would seem you'd need to send a subsequent request for deleting the branch; but the REST API for git isn't what I'd call comprehensive, and as far as I know there is no option for doing this.

So, IMO your best bet would be, after sending the request to abandon the pull request, engage the git cli to force-push deletion of the branch. Do note that this will delete the ref, but the commits will remain. To the best of my knowledge TFS doesn't do garbage collection, much less expose the option to force a gc run, so I know of no practical solution if you need the commits (and the tree/blob versions therein) to also be cleaned up.