-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit-purge-file.rb
58 lines (51 loc) · 1.28 KB
/
git-purge-file.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
config = "git-purge-file".get_config
[
-> () { # check external requirements
"git".check_program!
true
},
-> () { # arguments normalization
options = parse_args do |parser, opts|
parser.on("-p", "--path [PATH]",
"Path to file or directory that should be purged") do |path|
opts[:path] = path
end
end
config[:path] = options[:path] if options[:path]
true
},
-> () { # config normalization
"path needs to be provided".perr unless config[:path]
config[:path] = config[:path].to_pn
true
},
-> () {
"git".run "filter-branch",
"--tree-filter",
"rm -rf #{config[:path]}",
"--prune-empty",
"HEAD",
interactive: true
},
-> () {
output = StringIO.new
"git".run "for-each-ref",
"--format",
"%(refname)",
"refs/original/",
output: output
config[:refs] = output.string.trim.split "\n"
true
},
-> () {
status
config[:refs].each do |ref|
status &&= "git".run "update-ref", "-d", ref, interactive: true
end
status
},
-> () {
"git".run "gc", "--prune=all", "--aggressive", interactive: true
}
].do_all auto_exit_code: true
# vim: set filetype=ruby :