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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/src/git_status_tree.rb +33 -1
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b0823206680a82016025ca4859cd9d0b7baf30ec61c51e2f5201f0dceeac9d20
4
- data.tar.gz: 731c9421ae4eeffe679b3c65f2bc5816fe949aae33af6aa4082694eb8b133b66
3
+ metadata.gz: 92b497a283f3b3e3c260ea64423ad9350acc0973821ebad9b69fe2368cdf0324
4
+ data.tar.gz: 8fec32b7303b4de5e2390655b1d20ee53c4c7197cedba99fa17db348fbe942e8
5
5
  SHA512:
6
- metadata.gz: 050262f9aa55d5768e1a63dfa199f035f2a3cb34d519bd1f703fd2e0405cdef23c5440449e46c3087f3349360107de5045ef60a07052a9d15667905136b56f52
7
- data.tar.gz: cb498d741fbf7c4c2cf84475b0d69b0bf1857318e2ea45279dc5bc4fb54adcceb8e2fed576c66aa42e781de2cfdf7a9ba7be99a1686c4d77eb413740bd469aa7
6
+ metadata.gz: d551f8f7cb67163edde8680402d0092bb590ade73a4c4ec4ad97cf7551937e6d983f71e261eca8c5b27773bb9a51d7782a9c6096d80ef01a2afa4cd3947c74db
7
+ data.tar.gz: f1eb272a459af1b52b8c13c59fd1d510ff43c213692ed6159a53e4e468405b96711d3b5b7314acd6d2d45df7ae666c3a289149143381a50ba20d5e3fab659de0
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.5.0
1
+ 3.5.1
@@ -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)}`.split("\n")
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git-status-tree
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.5.0
4
+ version: 3.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wolfgang Teuber