github-linguist/linguist · warning · NotImplementedError
current_tree is deprecated
Error message
current_tree is deprecated
What it means
current_tree is the second legacy Rugged-specific helper on Linguist::Repository: it returns the commit's tree via repository.get_tree, but raises NotImplementedError ('current_tree is deprecated') whenever the injected source is not a Linguist::Source::RuggedRepository. As with read_index, the constructor only wraps raw Rugged repos; an injected custom Source::Repository leaves this path unavailable. The tree is an internal detail of stats computation — callers should use #language_stats/#cache rather than walking the tree themselves.
Source
Thrown at lib/linguist/repository.rb:137
#
# Returns a map of filename => [language, size]
def cache
@cache ||= begin
if @old_commit_oid == @commit_oid
@old_stats
else
compute_stats(@old_commit_oid, @old_stats)
end
end
end
def read_index
raise NotImplementedError, "read_index is deprecated" unless repository.is_a? Linguist::Source::RuggedRepository
repository.set_attribute_source(@commit_oid)
end
def current_tree
raise NotImplementedError, "current_tree is deprecated" unless repository.is_a? Linguist::Source::RuggedRepository
repository.get_tree(@commit_oid)
end
protected
def compute_stats(old_commit_oid, cache = nil)
return {} if repository.get_tree_size(@commit_oid, @max_tree_size) >= @max_tree_size
repository.set_attribute_source(@commit_oid)
diff = repository.diff(old_commit_oid, @commit_oid)
# Clear file map and fetch full diff if any .gitattributes files are changed
if cache && diff.each_delta.any? { |delta| File.basename(delta.new_file[:path]) == ".gitattributes" }
diff = repository.diff(nil, @commit_oid)
file_map = {}
else
file_map = cache ? cache.dup : {}
end
View on GitHub (pinned to b45dbe9b28)
Solutions
- Use the public API: `repo.language_stats` returns the language breakdown without needing the tree.
- If you must enumerate entries, add an equivalent accessor to your custom source class and call it on `repo.repository` directly.
- Gate legacy usage: `tree = repo.current_tree if repo.repository.is_a?(Linguist::Source::RuggedRepository)`.
- Delete references to current_tree when upgrading — it is explicitly marked deprecated and will not be extended to other sources.
Example fix
# before
linguist_repo.current_tree.each_blob { |b| analyze(b) }
# after
stats = linguist_repo.language_stats # { "Ruby" => 1234, ... } Defensive patterns
Strategy: type-guard
Validate before calling
def tree_via_source(linguist_repo) src = linguist_repo.repository return src.get_tree(linguist_repo.instance_variable_get(:@commit_oid)) if src.is_a?(Linguist::Source::RuggedRepository) src.respond_to?(:get_tree) ? src.get_tree : nil end
Type guard
def rugged_backed?(linguist_repo) linguist_repo.repository.is_a?(Linguist::Source::RuggedRepository) end
Try / catch
begin tree = linguist_repo.current_tree rescue NotImplementedError => e raise unless e.message =~ /current_tree is deprecated/ tree = nil # fall back to language_stats for whatever you needed the tree for end
Prevention
- Use repo.language_stats instead of walking current_tree yourself.
- If you need tree access on a custom source, expose it on your source class rather than via the deprecated helper.
- Search your codebase for `current_tree` when upgrading linguist 5.x+ — these calls now guard on the source type.
When it happens
Trigger: 1) Calling `repo.current_tree` on a Repository built around a custom Linguist::Source::Repository implementation. 2) Code ported from older linguist versions that used current_tree to enumerate blobs for analysis. 3) Specs with fake/stub sources (not RuggedRepository instances) exercising old helper calls.
Common situations: Version upgrades from pre-source-abstraction linguist to 5.x+ where internal helpers now guard on the source type; hosting applications injecting their own source adapter; scripts that enumerated `current_tree` blobs directly instead of using the stats API.
Related errors
- read_index is deprecated
- Duplicate language name: #{language.name}
- Duplicate language name: #{language.fs_name}
- Duplicate alias: #{name}
- Extension is missing a '.': #{extension.inspect}
AI-assisted analysis of github-linguist/linguist@b45dbe9b28 (2026-08-21).
Data as JSON: /api/errors/d0ffc1382f2b8628.
Report an issue: GitHub.