Deleting files via trees no longer works?

Based on this comment, I’ve been able to delete multiple files from a repo with the v3 api via:

  1. GET the parent tree recursively

  2. Remove the files I want to delete from the tree

  3. POST a new tree, using the parent tree sha as the base_tree

This used to work fine, but no longer does. It currently responds with “201 Created”, but just contains the parent tree (same sha, and still containing deleted files). Have there been any recent changes to the v3 api that may have caused this?

EDIT: this also breaks renaming files via trees

I just tested it and it worked fine. Here’s what I did:

  1. Create new directory directory in https://github.com/lee-dohm/test-repo with two files delete-this-file.txt and do-not-delete-this-file.txt (see result)
  2. Create a new tree object for directory that does not contain delete-this-file.txt
  3. Create a new tree object for / that points to all the same stuff except points to the new tree object created in step 2 for directory
  4. Create a commit object pointing to the tree object created in step 3 and the parent commit created in step 1
  5. Update the master branch to point to the new commit object created in step 4

You can see the final result in the repository.

One thing I did notice is that when creating the new tree objects, I needed to leave out the base_tree value.

I hope that helps!

1 Like

@lee-dohm thanks for the response!

One thing I did notice is that when creating the new tree objects, I needed to leave out the base_tree value.

This was the part I had wrong. I was passing the parent commit’s tree sha, but seems like doing so will fill in missing leafs from the base tree. My script definitely previously worked (improperly) withbase_tree, so maybe there was a recent update that fixed it?

Either way, leaving it out fixed my issue.

Thanks!

1 Like