Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: Creating a new tree with a null sha tree object fails #2836

Open
1 task done
Zaragor opened this issue Dec 20, 2023 · 1 comment
Open
1 task done

[BUG]: Creating a new tree with a null sha tree object fails #2836

Zaragor opened this issue Dec 20, 2023 · 1 comment
Labels
Type: Bug Something isn't working as documented Type: Support Any questions, information, or general needs around the SDK or GitHub APIs

Comments

@Zaragor
Copy link

Zaragor commented Dec 20, 2023

What happened?

I'd like to delete multiple files within one commit, so was constructing a tree with multiple objects with a null sha, as per documentation. I get an API error Must supply either tree.sha or tree.content. Request will be rejected if both are present.. When I run an identical API request via Postmark with sha set to null, it succeeds in creating the tree. When I run the request with sha not present, I see that API error.

I imagine its something in the serializer stripping out null fields, when in this case I would like them to be preserved.

I can't use the client.Repository.Content.DeleteFile api, as that creates a new commit for every file you delete.

Example failing code below.

var toDelete = new List<string>() { "file1", "file2" };
var repository = await client.Repository.Get("ORGID", "REPONAME");
var headOfDefault = await client.Git.Reference.Get(repository.Id, $"heads/{repository.DefaultBranch}");
var tree = new NewTree() {
    BaseTree = headOfDefault.Object.Sha
};
foreach (var file in toDelete) {
    tree.Tree.Add(
        new NewTreeItem() 
        {
            Type = TreeType.Blob,
            Mode = FileMode.File,
            Path = file
            Sha = null
        });
}
var newTree = await client Git.Tree.Create(repository.Id, tree);

Versions

Octokit 9.0.0 running on net6.0

Relevant log output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@Zaragor Zaragor added Status: Triage This is being looked at and prioritized Type: Bug Something isn't working as documented labels Dec 20, 2023
@nickfloyd nickfloyd added Type: Support Any questions, information, or general needs around the SDK or GitHub APIs and removed Status: Triage This is being looked at and prioritized labels Jan 4, 2024
@bifacil
Copy link

bifacil commented Feb 4, 2024

Reproduced here.😣

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Something isn't working as documented Type: Support Any questions, information, or general needs around the SDK or GitHub APIs
Projects
Status: 🔥 Backlog
Development

No branches or pull requests

3 participants