go-github icon indicating copy to clipboard operation
go-github copied to clipboard

docs: Clarify `CreateTree` semantics and `TreeEntry` usage

Open rogpeppe opened this issue 1 month ago • 1 comments

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

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

🤖 Generated with Claude Code

rogpeppe avatar Dec 11 '25 16:12 rogpeppe

Codecov Report

:white_check_mark: All modified and coverable lines are covered by tests. :white_check_mark: Project coverage is 92.48%. Comparing base (59f33d9) to head (d61fb68). :warning: 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           

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

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

codecov[bot] avatar Dec 11 '25 16:12 codecov[bot]

Thank you, @stevehipwell! Merging.

gmlewis avatar Dec 12 '25 14:12 gmlewis