git-status-tree 3.5.0 → 3.5.1
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/VERSION +1 -1
- data/src/git_status_tree.rb +33 -1
- 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: 92b497a283f3b3e3c260ea64423ad9350acc0973821ebad9b69fe2368cdf0324
|
|
4
|
+
data.tar.gz: 8fec32b7303b4de5e2390655b1d20ee53c4c7197cedba99fa17db348fbe942e8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d551f8f7cb67163edde8680402d0092bb590ade73a4c4ec4ad97cf7551937e6d983f71e261eca8c5b27773bb9a51d7782a9c6096d80ef01a2afa4cd3947c74db
|
|
7
|
+
data.tar.gz: f1eb272a459af1b52b8c13c59fd1d510ff43c213692ed6159a53e4e468405b96711d3b5b7314acd6d2d45df7ae666c3a289149143381a50ba20d5e3fab659de0
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
3.5.
|
|
1
|
+
3.5.1
|
data/src/git_status_tree.rb
CHANGED
|
@@ -13,7 +13,7 @@ class GitStatusTree
|
|
|
13
13
|
def initialize(options = {})
|
|
14
14
|
Node.indent = indent(options)
|
|
15
15
|
Node.collapse_dirs = collapse(options)
|
|
16
|
-
@files = `git status --porcelain#{untracked_files(options)}
|
|
16
|
+
@files = parse_status(`git status --porcelain -z#{untracked_files(options)}`)
|
|
17
17
|
@nodes = files.map { |file| Node.create_from_string file }
|
|
18
18
|
@tree = nodes.reduce { |a, i| (a + i).nodes[0] }
|
|
19
19
|
end
|
|
@@ -28,6 +28,38 @@ class GitStatusTree
|
|
|
28
28
|
|
|
29
29
|
private
|
|
30
30
|
|
|
31
|
+
# Parse NUL-terminated `git status --porcelain -z` output into porcelain
|
|
32
|
+
# entry strings. Unlike the default output, -z never quotes or escapes
|
|
33
|
+
# paths, so names with spaces, non-ASCII characters, quotes, backslashes
|
|
34
|
+
# or tabs survive intact. Rename/copy entries span two NUL-separated
|
|
35
|
+
# tokens ("<XY> <dest>\0<orig>\0") and are reassembled into the
|
|
36
|
+
# "<XY> <orig> -> <dest>" form the node parser expects.
|
|
37
|
+
def parse_status(raw)
|
|
38
|
+
# Paths are emitted as raw UTF-8 bytes; tag them so names display literally.
|
|
39
|
+
tokens = raw.force_encoding('UTF-8').split("\0")
|
|
40
|
+
files = []
|
|
41
|
+
index = 0
|
|
42
|
+
while index < tokens.length
|
|
43
|
+
entry = tokens[index]
|
|
44
|
+
index += 1
|
|
45
|
+
next if entry.nil? || entry.empty?
|
|
46
|
+
|
|
47
|
+
if rename_or_copy?(entry)
|
|
48
|
+
orig = tokens[index]
|
|
49
|
+
index += 1
|
|
50
|
+
files << "#{entry[0, 3]}#{orig} -> #{entry[3..]}"
|
|
51
|
+
else
|
|
52
|
+
files << entry
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
files
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def rename_or_copy?(entry)
|
|
59
|
+
status = entry[0, 2]
|
|
60
|
+
status.include?('R') || status.include?('C')
|
|
61
|
+
end
|
|
62
|
+
|
|
31
63
|
def indent(options)
|
|
32
64
|
indent = options[:indent] || config || 4
|
|
33
65
|
indent = 2 if indent < 2
|