Skip to content

Instantly share code, notes, and snippets.

@burke
Created May 2, 2023 20:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save burke/adbda0b3a58ca34832dad8289f58f063 to your computer and use it in GitHub Desktop.
Save burke/adbda0b3a58ca34832dad8289f58f063 to your computer and use it in GitHub Desktop.
#!ruby --disable-gems
require 'open3'
def find_git_root(curr = Dir.pwd)
abort('no git repository') if curr == '/'
return(curr) if File.exist?(File.join(curr, '.git'))
find_git_root(File.expand_path('..', curr))
end
Dir.chdir(find_git_root)
o, stat = Open3.capture2('git', 'ls-files')
abort('git ls-files failed') unless stat.success?
files = o.lines.map(&:chomp)
list = ARGV.include?('-l')
unless list
puts "---------------Contents of git repo: #{File.basename(Dir.pwd)}---------------"
puts "---------------REPOSITORY MANIFEST---------------"
files.each { |f| puts(f) }
end
IGNORE = [
/package-lock\.json$/,
/\.lock$/,
/\.ejson$/,
/^infrastructure\//,
]
def omit?(path, blob)
IGNORE.any? { |r| r =~ path } || likely_binary?(blob)
end
def likely_binary?(blob)
bytes = blob[1..1024].each_byte
total = bytes.count
high = bytes.count { |b| b > 127 }
bytes.size > 128 && high.to_f / total > 0.2
end
files.each do |f|
contents = File.read(f)
next if omit?(f, contents)
if list
puts f
else
puts("---------------#{f}---------------")
puts(contents)
end
end
Here's a full exported git repo:
{{repo}}
When I ask you for changes, I want you to show me just the parts to change with just enough surrounding context to be helpful.
{{request}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment