Created
May 2, 2023 20:43
-
-
Save burke/adbda0b3a58ca34832dad8289f58f063 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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