format-staged 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 80bea79a03480ca702efd9bec176a0a2e180e82e854c7300773b064bf4c46b1e
4
- data.tar.gz: 06356777c82f354560e700aef495929f1dc7e4d0d72c08456271a3b08fd3d8cc
3
+ metadata.gz: 1692442034aaff731e62e22677ccd3026d4e8e644c88fdcc4ec2df9db06521b7
4
+ data.tar.gz: a2f8d26b365c7c2b1597055490010398900335f0abc6e1dde9b6235adb6c9642
5
5
  SHA512:
6
- metadata.gz: bd2a7a026faf4ff75b34b69a26aba8df9ff9d18d15be75341c365a8c5bae010044010d2fe3976cd5b60ccc9e7f0d68c7a62955bc620c56b7ad3955779713ec95
7
- data.tar.gz: 126334604bfac8205438d64d597638490d560db058476f4a53b673f89f2b80cbc055a3f76863d5f6489b89f132140947794cb4a0cece89ea89ea287fe6c0c5f8
6
+ metadata.gz: e3bb54425caec06ca5ae575a9eb99726b57bd4974972a3db9a645f28cb199eb1e04f527305e4f2b6d1e0bd4abae2e7a5275041c2aa1c2b5baf37b9bfcec2bc44
7
+ data.tar.gz: e118755923b6a019cccc20e1354721692fd38fc6c1f6dc09013c47ab9a5d9959277f365362696111c7887faa74526477b8d140b654812a0152840aa9a91d6e34
@@ -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
- output = IO.popen(args, err: :err) do |io|
9
- if lines
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class FormatStaged
4
- VERSION = '0.0.2'
4
+ VERSION = '0.0.3'
5
5
  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.readlines.map(&:chomp)
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.first
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: format-staged
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sven Weidauer