format-staged 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/format-staged/io.rb +16 -14
- data/lib/format-staged/version.rb +1 -1
- data/lib/format_staged.rb +5 -8
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1692442034aaff731e62e22677ccd3026d4e8e644c88fdcc4ec2df9db06521b7
|
4
|
+
data.tar.gz: a2f8d26b365c7c2b1597055490010398900335f0abc6e1dde9b6235adb6c9642
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e3bb54425caec06ca5ae575a9eb99726b57bd4974972a3db9a645f28cb199eb1e04f527305e4f2b6d1e0bd4abae2e7a5275041c2aa1c2b5baf37b9bfcec2bc44
|
7
|
+
data.tar.gz: e118755923b6a019cccc20e1354721692fd38fc6c1f6dc09013c47ab9a5d9959277f365362696111c7887faa74526477b8d140b654812a0152840aa9a91d6e34
|
data/lib/format-staged/io.rb
CHANGED
@@ -2,22 +2,11 @@
|
|
2
2
|
|
3
3
|
require 'English'
|
4
4
|
class FormatStaged
|
5
|
-
def get_output(*args, lines: true)
|
5
|
+
def get_output(*args, lines: true, silent: false)
|
6
6
|
puts "> #{args.join(' ')}" if @verbose
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
io.readlines.map(&:chomp)
|
11
|
-
else
|
12
|
-
io.read
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
if @verbose && lines
|
17
|
-
output.each do |line|
|
18
|
-
puts "< #{line}"
|
19
|
-
end
|
20
|
-
end
|
8
|
+
r = IO.popen(args, err: :err)
|
9
|
+
output = read_output(r, lines: lines, silent: silent)
|
21
10
|
|
22
11
|
raise 'Failed to run command' unless $CHILD_STATUS.success?
|
23
12
|
|
@@ -40,4 +29,17 @@ class FormatStaged
|
|
40
29
|
|
41
30
|
[pid, r]
|
42
31
|
end
|
32
|
+
|
33
|
+
def read_output(r, lines: true, silent: false)
|
34
|
+
result = r.read
|
35
|
+
splits = result.split("\n")
|
36
|
+
if @verbose && !silent
|
37
|
+
splits.each do |line|
|
38
|
+
puts "< #{line}"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
r.close
|
42
|
+
|
43
|
+
lines ? splits : result
|
44
|
+
end
|
43
45
|
end
|
data/lib/format_staged.rb
CHANGED
@@ -67,12 +67,7 @@ class FormatStaged
|
|
67
67
|
pid2, r = pipe_command format_command, source: r
|
68
68
|
pid3, r = pipe_command 'git', 'hash-object', '-w', '--stdin', source: r
|
69
69
|
|
70
|
-
result = r.
|
71
|
-
if @verbose
|
72
|
-
result.each do |line|
|
73
|
-
puts "< #{line}"
|
74
|
-
end
|
75
|
-
end
|
70
|
+
result = read_output(r, lines: false).chomp
|
76
71
|
|
77
72
|
Process.wait pid1
|
78
73
|
raise "Cannot read #{file.dst_hash} from object database" unless $CHILD_STATUS.success?
|
@@ -83,7 +78,7 @@ class FormatStaged
|
|
83
78
|
Process.wait pid3
|
84
79
|
raise 'Error writing formatted file back to object database' unless $CHILD_STATUS.success? && !result.empty?
|
85
80
|
|
86
|
-
result
|
81
|
+
result
|
87
82
|
end
|
88
83
|
|
89
84
|
def object_is_empty(hash)
|
@@ -92,7 +87,7 @@ class FormatStaged
|
|
92
87
|
end
|
93
88
|
|
94
89
|
def patch_working_file(file, new_hash)
|
95
|
-
patch = get_output 'git', 'diff', file.dst_hash, new_hash, lines: false
|
90
|
+
patch = get_output 'git', 'diff', file.dst_hash, new_hash, lines: false, silent: true
|
96
91
|
patch.gsub! "a/#{file.dst_hash}", "a/#{file.src_path}"
|
97
92
|
patch.gsub! "b/#{new_hash}", "b/#{file.src_path}"
|
98
93
|
|
@@ -102,6 +97,8 @@ class FormatStaged
|
|
102
97
|
patch_out.write patch
|
103
98
|
patch_out.close
|
104
99
|
|
100
|
+
read_output r
|
101
|
+
|
105
102
|
Process.wait pid
|
106
103
|
raise 'Error applying patch' unless $CHILD_STATUS.success?
|
107
104
|
end
|