Skip to content

Commit 93cd90b

Browse files
justin808claude
andcommitted
Add outdated check to --status command
The --status command now checks if GitHub-based swapped gems are outdated and displays how many commits behind they are. This helps developers know when they need to refresh their cached dependencies. Features: - Automatically fetches and compares commits with remote branch - Shows number of commits behind for each outdated gem - Provides example command to update Example output: ⚠️ Outdated GitHub repositories detected: shakapacker (shakacode/shakapacker@justin808/early-hints) - 2 commit(s) behind 💡 To update: Re-run your swap command to fetch latest changes Example: bin/swap-deps --github 'shakacode/shakapacker#justin808/early-hints' 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent c014e36 commit 93cd90b

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

lib/demo_scripts/gem_swapper.rb

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,22 @@ def kill_watch_processes
138138
def show_status
139139
puts '📊 Swapped dependencies status:'
140140

141+
outdated_repos = []
142+
141143
each_demo do |demo_path|
142144
show_demo_status(demo_path)
145+
outdated_repos.concat(check_outdated_repos(demo_path))
146+
end
147+
148+
return unless outdated_repos.any?
149+
150+
puts "\n⚠️ Outdated GitHub repositories detected:"
151+
outdated_repos.uniq.each do |repo_info|
152+
commits = repo_info[:commits_behind]
153+
puts " #{repo_info[:gem_name]} (#{repo_info[:repo]}@#{repo_info[:ref]}) - #{commits} commit(s) behind"
143154
end
155+
puts "\n💡 To update: Re-run your swap command to fetch latest changes"
156+
puts " Example: bin/swap-deps --github '#{outdated_repos.first[:repo]}##{outdated_repos.first[:ref]}'"
144157
end
145158

146159
# CLI entry point: Display cache information including location, size, and cached repositories
@@ -361,6 +374,50 @@ def detect_git_branch(path)
361374
nil
362375
end
363376

377+
# Check if any GitHub-based swapped gems are outdated
378+
def check_outdated_repos(demo_path)
379+
gemfile_path = File.join(demo_path, 'Gemfile')
380+
return [] unless File.exist?(gemfile_path)
381+
382+
swapped_gems = detect_swapped_gems(gemfile_path)
383+
outdated = []
384+
385+
swapped_gems.each do |gem|
386+
next unless gem[:type] == 'github'
387+
388+
repo, ref = gem[:path].split('@', 2)
389+
cache_path = github_cache_path(gem[:name], { repo: repo, branch: ref })
390+
391+
next unless File.directory?(cache_path)
392+
393+
commits_behind = check_commits_behind(cache_path, ref)
394+
next unless commits_behind&.positive?
395+
396+
outdated << {
397+
gem_name: gem[:name],
398+
repo: repo,
399+
ref: ref,
400+
commits_behind: commits_behind
401+
}
402+
end
403+
404+
outdated
405+
end
406+
407+
# Check how many commits behind the local cache is from the remote branch
408+
def check_commits_behind(cache_path, branch)
409+
Dir.chdir(cache_path) do
410+
# Fetch latest without output
411+
system('git', 'fetch', 'origin', branch, out: '/dev/null', err: '/dev/null')
412+
413+
# Count commits between local and remote
414+
output, status = Open3.capture2('git', 'rev-list', '--count', "HEAD..origin/#{branch}")
415+
return status.success? ? output.strip.to_i : nil
416+
end
417+
rescue StandardError
418+
nil
419+
end
420+
364421
def cache_repo_dirs
365422
return [] unless File.directory?(CACHE_DIR)
366423

0 commit comments

Comments
 (0)