Skip to content

Conversation

@rogpeppe
Copy link
Contributor

Summary

This PR improves the documentation for CreateTree and TreeEntry to clarify several behaviors that are not obvious from the existing docs:

  • Merge semantics: When baseTree is provided, entries are merged with that tree - paths not mentioned in entries are preserved from the base tree
  • Duplicate entries: If the same path appears multiple times in entries, the last entry wins
  • File/directory deletion: To delete an entry, set both SHA and Content to nil; this works for both files and entire directories
  • Type/Mode ignored on delete: When deleting, the Type and Mode fields are ignored by the API; only Path is required
  • Content vs SHA: Clarifies when to use Content (small text files) vs SHA (reference to existing blob), with a reference to CreateBlob for binary files

These behaviors were verified experimentally against the GitHub API.

Test plan

  • Documentation-only change, no code changes
  • Existing tests pass (go test ./github/... -run TestGitService_.*Tree)

🤖 Generated with Claude Code

@gmlewis gmlewis changed the title docs: clarify CreateTree semantics and TreeEntry usage docs: Clarify CreateTree semantics and TreeEntry usage Dec 11, 2025
@codecov
Copy link

codecov bot commented Dec 11, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.48%. Comparing base (59f33d9) to head (d61fb68).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #3877   +/-   ##
=======================================
  Coverage   92.48%   92.48%           
=======================================
  Files         200      200           
  Lines       14564    14564           
=======================================
  Hits        13469    13469           
  Misses        895      895           
  Partials      200      200           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Collaborator

@gmlewis gmlewis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @rogpeppe!
I saw the "sha": null first and wanted to make it render distinctively, so then thought we might as well try to be consistent, so if you could go through and back-tick all the code elements, that would be great, thanks! (I stopped flagging them, but you can do the rest.)
The we should be ready for a second LGTM+Approval from any other contributor to this repo before merging.

cc: @stevehipwell - @alexandear - @zyfy29

// When used with [GitService.CreateTree], set Content for small text files,
// or set SHA to reference an existing blob (use [GitService.CreateBlob] for
// binary files or large content). To delete an entry, set both Content and SHA
// to nil; the entry will be serialized with "sha": null which the API interprets
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// to nil; the entry will be serialized with "sha": null which the API interprets
// to `nil`; the entry will be serialized with `"sha": null` which the API interprets

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done the second of those two.

Comment on lines +35 to +36
// or set SHA to reference an existing blob (use [GitService.CreateBlob] for
// binary files or large content). To delete an entry, set both Content and SHA
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// or set SHA to reference an existing blob (use [GitService.CreateBlob] for
// binary files or large content). To delete an entry, set both Content and SHA
// or set `SHA` to reference an existing blob (use [GitService.CreateBlob] for
// binary files or large content). To delete an entry, set both `Content` and `SHA`

Copy link
Contributor Author

@rogpeppe rogpeppe Dec 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a look at current precedent and it seems to me that it fits more with Go convention and existing conventions in this package not to quote field names or the Go value "nil". For example all the Get* methods mention the field in question without quoting it, and there are many examples of using "nil" in doc comments in the stdlib without quoting.

I totally agree with backquoting the JSON fragment however.

Happy to make the changes anyway if you decide otherwise.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a look at current precedent and it seems to me that it fits more with Go convention and existing conventions in this package not to quote field names or the Go value "nil". For example all the Get* methods mention the field in question without quoting it, and there are many examples of using "nil" in doc comments in the stdlib without quoting.

I totally agree with backquoting the JSON fragment however.

Happy to make the changes anyway if you decide otherwise.

True, that's a good point. Go ahead and follow the Go convention. Thanks, @rogpeppe!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Following the Go convention, you would wrap Content and SHA in square brackets, right?

  • [Content]
  • [SHA]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That wouldn't fit with the doc links syntax. I guess we could use [TreeEntry.Content] and [TreeEntry.SHA] instead, but given that other doc comments in this package already refer to fields without such a qualifier, that seems a bit unnecessary to me. Happy to change to do it anyway if you think it's worthwhile.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I'm fine with that.

To fix this properly, it would probably mean that we should make the entire repo consistent with the Go doc links syntax, which would be a huge undertaking. If you feel like filing an issue, that would be great, but let's proceed as you currently have it. Thanks, @rogpeppe!

@gmlewis gmlewis added the NeedsReview PR is awaiting a review before merging. label Dec 11, 2025
Document the merge behavior when baseTree is provided, how to delete
files and directories by setting SHA and Content to nil, and that
duplicate paths result in last-entry-wins behavior.

Also document on TreeEntry how to use Content vs SHA, referencing
CreateBlob for binary files, and that Type/Mode are ignored when
deleting.

Signed-off-by: Roger Peppe <rogpeppe@gmail.com>
@rogpeppe rogpeppe force-pushed the improve-createtree-docs branch from 3dc95f0 to d61fb68 Compare December 11, 2025 17:29
Copy link
Contributor

@stevehipwell stevehipwell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@gmlewis
Copy link
Collaborator

gmlewis commented Dec 12, 2025

Thank you, @stevehipwell!
Merging.

@gmlewis gmlewis merged commit 07ddcd9 into google:master Dec 12, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

NeedsReview PR is awaiting a review before merging.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants