git 4.4.6 → 6.0.0

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 (275) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +1 -0
  3. data/CHANGELOG.md +348 -39
  4. data/CONTRIBUTING.md +1014 -144
  5. data/README.md +386 -504
  6. data/UPGRADING.md +1822 -0
  7. data/git.gemspec +102 -22
  8. data/lib/git/author_info.rb +65 -0
  9. data/lib/git/branch_delete_failure.rb +34 -0
  10. data/lib/git/branch_delete_result.rb +66 -0
  11. data/lib/git/branch_info.rb +237 -0
  12. data/lib/git/command_line/base.rb +247 -0
  13. data/lib/git/command_line/capturing.rb +308 -0
  14. data/lib/git/command_line/result.rb +88 -0
  15. data/lib/git/command_line/streaming.rb +236 -0
  16. data/lib/git/command_line.rb +45 -323
  17. data/lib/git/commands/add.rb +139 -0
  18. data/lib/git/commands/am/abort.rb +43 -0
  19. data/lib/git/commands/am/apply.rb +263 -0
  20. data/lib/git/commands/am/continue.rb +43 -0
  21. data/lib/git/commands/am/quit.rb +43 -0
  22. data/lib/git/commands/am/retry.rb +49 -0
  23. data/lib/git/commands/am/show_current_patch.rb +64 -0
  24. data/lib/git/commands/am/skip.rb +42 -0
  25. data/lib/git/commands/am.rb +33 -0
  26. data/lib/git/commands/apply.rb +242 -0
  27. data/lib/git/commands/archive/list_formats.rb +46 -0
  28. data/lib/git/commands/archive.rb +145 -0
  29. data/lib/git/commands/arguments.rb +4521 -0
  30. data/lib/git/commands/base.rb +522 -0
  31. data/lib/git/commands/branch/copy.rb +102 -0
  32. data/lib/git/commands/branch/create.rb +177 -0
  33. data/lib/git/commands/branch/delete.rb +88 -0
  34. data/lib/git/commands/branch/list.rb +178 -0
  35. data/lib/git/commands/branch/move.rb +102 -0
  36. data/lib/git/commands/branch/set_upstream.rb +86 -0
  37. data/lib/git/commands/branch/show_current.rb +49 -0
  38. data/lib/git/commands/branch/unset_upstream.rb +53 -0
  39. data/lib/git/commands/branch.rb +34 -0
  40. data/lib/git/commands/cat_file/batch.rb +385 -0
  41. data/lib/git/commands/cat_file/filtered.rb +105 -0
  42. data/lib/git/commands/cat_file/raw.rb +203 -0
  43. data/lib/git/commands/cat_file.rb +49 -0
  44. data/lib/git/commands/checkout/branch.rb +153 -0
  45. data/lib/git/commands/checkout/files.rb +116 -0
  46. data/lib/git/commands/checkout.rb +38 -0
  47. data/lib/git/commands/checkout_index.rb +106 -0
  48. data/lib/git/commands/clean.rb +102 -0
  49. data/lib/git/commands/clone.rb +241 -0
  50. data/lib/git/commands/commit.rb +273 -0
  51. data/lib/git/commands/commit_tree.rb +101 -0
  52. data/lib/git/commands/config_option_syntax/add.rb +86 -0
  53. data/lib/git/commands/config_option_syntax/get.rb +121 -0
  54. data/lib/git/commands/config_option_syntax/get_all.rb +118 -0
  55. data/lib/git/commands/config_option_syntax/get_color.rb +95 -0
  56. data/lib/git/commands/config_option_syntax/get_color_bool.rb +96 -0
  57. data/lib/git/commands/config_option_syntax/get_regexp.rb +119 -0
  58. data/lib/git/commands/config_option_syntax/get_urlmatch.rb +111 -0
  59. data/lib/git/commands/config_option_syntax/list.rb +111 -0
  60. data/lib/git/commands/config_option_syntax/remove_section.rb +79 -0
  61. data/lib/git/commands/config_option_syntax/rename_section.rb +83 -0
  62. data/lib/git/commands/config_option_syntax/replace_all.rb +109 -0
  63. data/lib/git/commands/config_option_syntax/set.rb +119 -0
  64. data/lib/git/commands/config_option_syntax/unset.rb +92 -0
  65. data/lib/git/commands/config_option_syntax/unset_all.rb +94 -0
  66. data/lib/git/commands/config_option_syntax.rb +56 -0
  67. data/lib/git/commands/describe.rb +156 -0
  68. data/lib/git/commands/diff.rb +657 -0
  69. data/lib/git/commands/diff_files.rb +519 -0
  70. data/lib/git/commands/diff_index.rb +499 -0
  71. data/lib/git/commands/fetch.rb +354 -0
  72. data/lib/git/commands/fsck.rb +138 -0
  73. data/lib/git/commands/gc.rb +134 -0
  74. data/lib/git/commands/grep.rb +339 -0
  75. data/lib/git/commands/init.rb +101 -0
  76. data/lib/git/commands/log.rb +634 -0
  77. data/lib/git/commands/ls_files.rb +195 -0
  78. data/lib/git/commands/ls_remote.rb +161 -0
  79. data/lib/git/commands/ls_tree.rb +135 -0
  80. data/lib/git/commands/maintenance/register.rb +73 -0
  81. data/lib/git/commands/maintenance/run.rb +105 -0
  82. data/lib/git/commands/maintenance/start.rb +67 -0
  83. data/lib/git/commands/maintenance/stop.rb +56 -0
  84. data/lib/git/commands/maintenance/unregister.rb +80 -0
  85. data/lib/git/commands/maintenance.rb +29 -0
  86. data/lib/git/commands/merge/abort.rb +44 -0
  87. data/lib/git/commands/merge/continue.rb +44 -0
  88. data/lib/git/commands/merge/quit.rb +46 -0
  89. data/lib/git/commands/merge/start.rb +250 -0
  90. data/lib/git/commands/merge.rb +28 -0
  91. data/lib/git/commands/merge_base.rb +91 -0
  92. data/lib/git/commands/mv.rb +82 -0
  93. data/lib/git/commands/name_rev.rb +119 -0
  94. data/lib/git/commands/pull.rb +382 -0
  95. data/lib/git/commands/push.rb +251 -0
  96. data/lib/git/commands/read_tree.rb +154 -0
  97. data/lib/git/commands/remote/add.rb +96 -0
  98. data/lib/git/commands/remote/get_url.rb +68 -0
  99. data/lib/git/commands/remote/list.rb +56 -0
  100. data/lib/git/commands/remote/prune.rb +63 -0
  101. data/lib/git/commands/remote/remove.rb +52 -0
  102. data/lib/git/commands/remote/rename.rb +76 -0
  103. data/lib/git/commands/remote/set_branches.rb +70 -0
  104. data/lib/git/commands/remote/set_head.rb +89 -0
  105. data/lib/git/commands/remote/set_url.rb +78 -0
  106. data/lib/git/commands/remote/set_url_add.rb +70 -0
  107. data/lib/git/commands/remote/set_url_delete.rb +71 -0
  108. data/lib/git/commands/remote/show.rb +77 -0
  109. data/lib/git/commands/remote/update.rb +79 -0
  110. data/lib/git/commands/remote.rb +42 -0
  111. data/lib/git/commands/repack.rb +281 -0
  112. data/lib/git/commands/reset.rb +154 -0
  113. data/lib/git/commands/rev_parse.rb +304 -0
  114. data/lib/git/commands/revert/abort.rb +45 -0
  115. data/lib/git/commands/revert/continue.rb +62 -0
  116. data/lib/git/commands/revert/quit.rb +47 -0
  117. data/lib/git/commands/revert/skip.rb +44 -0
  118. data/lib/git/commands/revert/start.rb +158 -0
  119. data/lib/git/commands/revert.rb +29 -0
  120. data/lib/git/commands/rm.rb +113 -0
  121. data/lib/git/commands/show.rb +632 -0
  122. data/lib/git/commands/show_ref/exclude_existing.rb +119 -0
  123. data/lib/git/commands/show_ref/exists.rb +75 -0
  124. data/lib/git/commands/show_ref/list.rb +149 -0
  125. data/lib/git/commands/show_ref/verify.rb +122 -0
  126. data/lib/git/commands/show_ref.rb +42 -0
  127. data/lib/git/commands/stash/apply.rb +81 -0
  128. data/lib/git/commands/stash/branch.rb +67 -0
  129. data/lib/git/commands/stash/clear.rb +43 -0
  130. data/lib/git/commands/stash/create.rb +60 -0
  131. data/lib/git/commands/stash/drop.rb +73 -0
  132. data/lib/git/commands/stash/list.rb +43 -0
  133. data/lib/git/commands/stash/pop.rb +87 -0
  134. data/lib/git/commands/stash/push.rb +112 -0
  135. data/lib/git/commands/stash/show.rb +158 -0
  136. data/lib/git/commands/stash/store.rb +72 -0
  137. data/lib/git/commands/stash.rb +38 -0
  138. data/lib/git/commands/status.rb +174 -0
  139. data/lib/git/commands/symbolic_ref/delete.rb +72 -0
  140. data/lib/git/commands/symbolic_ref/read.rb +99 -0
  141. data/lib/git/commands/symbolic_ref/update.rb +79 -0
  142. data/lib/git/commands/symbolic_ref.rb +38 -0
  143. data/lib/git/commands/tag/create.rb +142 -0
  144. data/lib/git/commands/tag/delete.rb +57 -0
  145. data/lib/git/commands/tag/list.rb +146 -0
  146. data/lib/git/commands/tag/verify.rb +71 -0
  147. data/lib/git/commands/tag.rb +26 -0
  148. data/lib/git/commands/update_ref/batch.rb +145 -0
  149. data/lib/git/commands/update_ref/delete.rb +90 -0
  150. data/lib/git/commands/update_ref/update.rb +103 -0
  151. data/lib/git/commands/update_ref.rb +42 -0
  152. data/lib/git/commands/version.rb +60 -0
  153. data/lib/git/commands/worktree/add.rb +139 -0
  154. data/lib/git/commands/worktree/list.rb +64 -0
  155. data/lib/git/commands/worktree/lock.rb +58 -0
  156. data/lib/git/commands/worktree/management_base.rb +51 -0
  157. data/lib/git/commands/worktree/move.rb +66 -0
  158. data/lib/git/commands/worktree/prune.rb +67 -0
  159. data/lib/git/commands/worktree/remove.rb +63 -0
  160. data/lib/git/commands/worktree/repair.rb +71 -0
  161. data/lib/git/commands/worktree/unlock.rb +47 -0
  162. data/lib/git/commands/worktree.rb +43 -0
  163. data/lib/git/commands/write_tree.rb +68 -0
  164. data/lib/git/commands.rb +88 -0
  165. data/lib/git/config.rb +64 -1
  166. data/lib/git/config_entry_info.rb +106 -0
  167. data/lib/git/configuring.rb +795 -0
  168. data/lib/git/detached_head_info.rb +57 -0
  169. data/lib/git/diff.rb +295 -12
  170. data/lib/git/diff_file_numstat_info.rb +31 -0
  171. data/lib/git/diff_file_patch_info.rb +136 -0
  172. data/lib/git/diff_file_raw_info.rb +129 -0
  173. data/lib/git/diff_info.rb +162 -0
  174. data/lib/git/diff_path_status.rb +80 -19
  175. data/lib/git/diff_result.rb +34 -0
  176. data/lib/git/diff_stats.rb +66 -14
  177. data/lib/git/dirstat_info.rb +102 -0
  178. data/lib/git/encoding_utils.rb +57 -1
  179. data/lib/git/errors.rb +107 -26
  180. data/lib/git/escaped_path.rb +55 -3
  181. data/lib/git/execution_context/global.rb +31 -0
  182. data/lib/git/execution_context/repository.rb +151 -0
  183. data/lib/git/execution_context.rb +559 -0
  184. data/lib/git/factories.rb +1049 -0
  185. data/lib/git/file_ref.rb +77 -0
  186. data/lib/git/fsck_object.rb +17 -9
  187. data/lib/git/fsck_result.rb +27 -16
  188. data/lib/git/log.rb +172 -65
  189. data/lib/git/object.rb +323 -108
  190. data/lib/git/parsers/branch.rb +240 -0
  191. data/lib/git/parsers/cat_file.rb +111 -0
  192. data/lib/git/parsers/config_entry.rb +110 -0
  193. data/lib/git/parsers/diff.rb +792 -0
  194. data/lib/git/parsers/fsck.rb +144 -0
  195. data/lib/git/parsers/grep.rb +42 -0
  196. data/lib/git/parsers/ls_remote.rb +79 -0
  197. data/lib/git/parsers/ls_tree.rb +58 -0
  198. data/lib/git/parsers/remote.rb +162 -0
  199. data/lib/git/parsers/stash.rb +292 -0
  200. data/lib/git/parsers/status.rb +251 -0
  201. data/lib/git/parsers/tag.rb +341 -0
  202. data/lib/git/parsers/worktree.rb +185 -0
  203. data/lib/git/path_resolver.rb +274 -0
  204. data/lib/git/remote_info.rb +203 -0
  205. data/lib/git/repository/branching.rb +796 -0
  206. data/lib/git/repository/committing.rb +221 -0
  207. data/lib/git/repository/context_helpers.rb +454 -0
  208. data/lib/git/repository/diffing.rb +743 -0
  209. data/lib/git/repository/inspecting.rb +252 -0
  210. data/lib/git/repository/logging.rb +410 -0
  211. data/lib/git/repository/maintenance.rb +65 -0
  212. data/lib/git/repository/merging.rb +429 -0
  213. data/lib/git/repository/object_operations.rb +1334 -0
  214. data/lib/git/repository/remote_operations.rb +772 -0
  215. data/lib/git/repository/shared_private.rb +120 -0
  216. data/lib/git/repository/staging.rb +409 -0
  217. data/lib/git/repository/stashing.rb +619 -0
  218. data/lib/git/repository/status_operations.rb +196 -0
  219. data/lib/git/repository/worktree_operations.rb +252 -0
  220. data/lib/git/repository.rb +204 -1
  221. data/lib/git/stash_info.rb +102 -0
  222. data/lib/git/status_file_info.rb +258 -0
  223. data/lib/git/status_info.rb +189 -0
  224. data/lib/git/system_call_guard.rb +95 -0
  225. data/lib/git/tag_delete_failure.rb +34 -0
  226. data/lib/git/tag_delete_result.rb +66 -0
  227. data/lib/git/tag_info.rb +99 -0
  228. data/lib/git/url.rb +12 -5
  229. data/lib/git/version.rb +111 -2
  230. data/lib/git/version_constraint.rb +85 -0
  231. data/lib/git/worktree_info.rb +128 -0
  232. data/lib/git.rb +319 -332
  233. metadata +318 -74
  234. data/.commitlintrc.yml +0 -38
  235. data/.github/copilot-instructions.md +0 -2733
  236. data/.github/issue_template.md +0 -15
  237. data/.github/pull_request_template.md +0 -17
  238. data/.github/workflows/continuous_integration.yml +0 -120
  239. data/.github/workflows/enforce_conventional_commits.yml +0 -29
  240. data/.github/workflows/experimental_continuous_integration.yml +0 -59
  241. data/.github/workflows/release.yml +0 -53
  242. data/.gitignore +0 -15
  243. data/.husky/commit-msg +0 -1
  244. data/.release-please-manifest.json +0 -3
  245. data/.rubocop.yml +0 -55
  246. data/.rubocop_todo.yml +0 -12
  247. data/Gemfile +0 -5
  248. data/Rakefile +0 -18
  249. data/lib/git/args_builder.rb +0 -111
  250. data/lib/git/author.rb +0 -16
  251. data/lib/git/base.rb +0 -1140
  252. data/lib/git/branch.rb +0 -423
  253. data/lib/git/branches.rb +0 -68
  254. data/lib/git/command_line_result.rb +0 -92
  255. data/lib/git/index.rb +0 -6
  256. data/lib/git/lib.rb +0 -2333
  257. data/lib/git/path.rb +0 -38
  258. data/lib/git/remote.rb +0 -39
  259. data/lib/git/stash.rb +0 -26
  260. data/lib/git/stashes.rb +0 -56
  261. data/lib/git/status.rb +0 -159
  262. data/lib/git/working_directory.rb +0 -6
  263. data/lib/git/worktree.rb +0 -39
  264. data/lib/git/worktrees.rb +0 -47
  265. data/package.json +0 -10
  266. data/redesign/1_architecture_existing.md +0 -66
  267. data/redesign/2_architecture_redesign.md +0 -130
  268. data/redesign/3_architecture_implementation.md +0 -138
  269. data/redesign/index.md +0 -34
  270. data/release-please-config.json +0 -36
  271. data/tasks/gem_tasks.rake +0 -10
  272. data/tasks/rubocop.rake +0 -12
  273. data/tasks/test.rake +0 -13
  274. data/tasks/test_gem.rake +0 -12
  275. data/tasks/yard.rake +0 -23
@@ -0,0 +1,743 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'pathname'
4
+ require 'git/commands/diff'
5
+ require 'git/commands/diff_files'
6
+ require 'git/commands/diff_index'
7
+ require 'git/commands/status'
8
+ require 'git/diff'
9
+ require 'git/diff_path_status'
10
+ require 'git/diff_stats'
11
+ require 'git/escaped_path'
12
+ require 'git/repository/shared_private'
13
+
14
+ module Git
15
+ class Repository
16
+ # Facade methods for comparing commits and trees using `git diff`
17
+ #
18
+ # Included by {Git::Repository}.
19
+ #
20
+ # @api private
21
+ #
22
+ module Diffing
23
+ # Option keys accepted by {#diff_full}
24
+ #
25
+ # @return [Array<Symbol>]
26
+ #
27
+ # @api private
28
+ #
29
+ DIFF_FULL_ALLOWED_OPTS = %i[path_limiter].freeze
30
+ private_constant :DIFF_FULL_ALLOWED_OPTS
31
+
32
+ # Returns the full unified diff patch text between two trees
33
+ #
34
+ # Compares (1) two commits, (2) a commit against the working tree, or (3) the
35
+ # index against the working tree using `git diff -p`, and returns the raw
36
+ # unified diff patch output.
37
+ #
38
+ # **Comparing two commits**
39
+ #
40
+ # When both obj1 and obj2 are provided, the comparison is between those two
41
+ # refs (commits, tags, branches, etc.).
42
+ #
43
+ # **Comparing a commit against the working tree**
44
+ #
45
+ # When only obj1 is provided (and isn't nil), the comparison is between obj1 and
46
+ # the working tree; the patch reflects all changes since obj1.
47
+ #
48
+ # **Comparing the index against the working tree**
49
+ #
50
+ # When obj1 is explicitly `nil` then obj2 must be omitted or `nil`. In this case,
51
+ # the comparison is between the index and the working tree; the patch reflects
52
+ # unstaged changes.
53
+ #
54
+ # @example Get the working tree patch since HEAD
55
+ # repo.diff_full #=> "diff --git a/lib/foo.rb b/lib/foo.rb\n..."
56
+ #
57
+ # @example Compare two specific commits
58
+ # repo.diff_full('abc1234', 'def5678')
59
+ #
60
+ # @example Get unstaged changes (index vs. working tree)
61
+ # repo.diff_full(nil)
62
+ #
63
+ # @example Limit the diff to a sub-path
64
+ # repo.diff_full('HEAD~1', 'HEAD', path_limiter: 'lib/')
65
+ #
66
+ # @param obj1 [String, nil] the first commit or object to compare; defaults to
67
+ # `'HEAD'`
68
+ #
69
+ # @param obj2 [String, nil] the second commit or object to compare
70
+ #
71
+ # @param opts [Hash] options to filter the diff
72
+ #
73
+ # @option opts [String, Pathname, Array<String, Pathname>, nil] :path_limiter (nil)
74
+ # limit the diff to the given path(s)
75
+ #
76
+ # @return [String] the unified diff patch output
77
+ #
78
+ # @raise [ArgumentError] if unsupported options are provided
79
+ #
80
+ # @raise [ArgumentError] if `obj1` is `nil` but `obj2` is not OR if `obj1` or `obj2` starts with `"-"`
81
+ #
82
+ # @raise [Git::FailedError] if git exits outside the allowed range (exit code > 2)
83
+ #
84
+ # @see https://git-scm.com/docs/git-diff git-diff documentation
85
+ #
86
+ def diff_full(obj1 = 'HEAD', obj2 = nil, opts = {})
87
+ SharedPrivate.assert_valid_opts!(DIFF_FULL_ALLOWED_OPTS, **opts)
88
+ raise ArgumentError, 'Invalid arguments: obj1 is nil but obj2 is not' if obj1.nil? && !obj2.nil?
89
+
90
+ pathspecs = Private.normalize_pathspecs(opts[:path_limiter], 'path limiter')
91
+ result = Git::Commands::Diff.new(@execution_context).call(
92
+ *[obj1, obj2].compact,
93
+ patch: true, numstat: true, shortstat: true,
94
+ src_prefix: 'a/', dst_prefix: 'b/',
95
+ path: pathspecs
96
+ )
97
+ Private.extract_patch_text(result.stdout)
98
+ end
99
+
100
+ # Option keys accepted by {#diff_numstat}
101
+ #
102
+ # @return [Array<Symbol>]
103
+ #
104
+ # @api private
105
+ #
106
+ DIFF_NUMSTAT_ALLOWED_OPTS = %i[path_limiter].freeze
107
+ private_constant :DIFF_NUMSTAT_ALLOWED_OPTS
108
+
109
+ # Returns per-file insertion/deletion counts and totals between two trees
110
+ #
111
+ # Compares (1) two commits, (2) a commit against the working tree, or (3) the
112
+ # index against the working tree using `git diff --numstat`, and returns a
113
+ # structured hash of per-file insertion and deletion line counts together with
114
+ # aggregate totals.
115
+ #
116
+ # **Comparing two commits**
117
+ #
118
+ # When both obj1 and obj2 are provided, the comparison is between those two
119
+ # refs (commits, tags, branches, etc.).
120
+ #
121
+ # **Comparing a commit against the working tree**
122
+ #
123
+ # When only obj1 is provided (and isn't nil), the comparison is between obj1 and
124
+ # the working tree; the stats reflect all changes since obj1.
125
+ #
126
+ # **Comparing the index against the working tree**
127
+ #
128
+ # When obj1 is explicitly `nil` then obj2 must be omitted or `nil`. In this case,
129
+ # the comparison is between the index and the working tree; the stats reflect
130
+ # unstaged changes.
131
+ #
132
+ # @example Compare two specific commits
133
+ # repo.diff_numstat('abc1234', 'def5678')
134
+ #
135
+ # @example Get working tree changes since HEAD
136
+ # repo.diff_numstat
137
+ # #=> {
138
+ # # total: { insertions: 5, deletions: 2, lines: 7, files: 1 },
139
+ # # files: { "lib/foo.rb" => { insertions: 5, deletions: 2 } }
140
+ # # }
141
+ #
142
+ # @example Get unstaged changes (index vs. working tree)
143
+ # repo.diff_numstat(nil) #=> { ... }
144
+ #
145
+ # @example Limit the stats to a sub-path
146
+ # repo.diff_numstat('HEAD~1', 'HEAD', path_limiter: 'lib/')
147
+ #
148
+ # @param obj1 [String, nil] the first commit or object to compare; defaults to
149
+ # `'HEAD'`
150
+ #
151
+ # @param obj2 [String, nil] the second commit or object to compare
152
+ #
153
+ # @param opts [Hash] options to filter the diff
154
+ #
155
+ # @option opts [String, Pathname, Array<String, Pathname>, nil] :path_limiter (nil)
156
+ # limit the stats to the given path(s)
157
+ #
158
+ # @return [Hash] per-file insertion and deletion counts plus aggregate totals
159
+ #
160
+ # ```
161
+ # {
162
+ # total: { insertions: Integer, deletions: Integer, lines: Integer, files: Integer },
163
+ # files: { "path/to/file" => { insertions: Integer, deletions: Integer } }
164
+ # }
165
+ # ```
166
+ #
167
+ # @raise [ArgumentError] if unsupported options are provided
168
+ #
169
+ # @raise [ArgumentError] if `obj1` is `nil` but `obj2` is not OR if `obj1` or `obj2` starts with `"-"`
170
+ #
171
+ # @raise [Git::FailedError] if git exits outside the allowed range (exit code > 2)
172
+ #
173
+ # @see https://git-scm.com/docs/git-diff git-diff documentation
174
+ #
175
+ def diff_numstat(obj1 = 'HEAD', obj2 = nil, opts = {})
176
+ SharedPrivate.assert_valid_opts!(DIFF_NUMSTAT_ALLOWED_OPTS, **opts)
177
+ raise ArgumentError, 'Invalid arguments: obj1 is nil but obj2 is not' if obj1.nil? && !obj2.nil?
178
+
179
+ pathspecs = Private.normalize_pathspecs(opts[:path_limiter], 'path limiter')
180
+ result = Git::Commands::Diff.new(@execution_context).call(
181
+ *[obj1, obj2].compact,
182
+ numstat: true, shortstat: true, src_prefix: 'a/', dst_prefix: 'b/',
183
+ path: pathspecs
184
+ )
185
+ Private.parse_numstat_output(result.stdout)
186
+ end
187
+
188
+ # Option keys accepted by {#diff_stats}
189
+ #
190
+ # @return [Array<Symbol>]
191
+ #
192
+ # @api private
193
+ #
194
+ DIFF_STATS_ALLOWED_OPTS = %i[path_limiter].freeze
195
+ private_constant :DIFF_STATS_ALLOWED_OPTS
196
+
197
+ # Returns the stats between two trees as a {Git::DiffStats} object
198
+ #
199
+ # Compares (1) two commits, (2) a commit against the working tree, or (3) the
200
+ # index against the working tree and constructs a lazy {Git::DiffStats} that
201
+ # computes per-file insertion and deletion counts on demand when its accessor
202
+ # methods are called.
203
+ #
204
+ # **Comparing two commits**
205
+ #
206
+ # When both obj1 and obj2 are provided, the comparison is between those two
207
+ # refs (commits, tags, branches, etc.).
208
+ #
209
+ # **Comparing a commit against the working tree**
210
+ #
211
+ # When only obj1 is provided (and isn't nil), the comparison is between obj1 and
212
+ # the working tree; the stats reflect all changes since obj1.
213
+ #
214
+ # **Comparing the index against the working tree**
215
+ #
216
+ # When obj1 is explicitly `nil` then obj2 must be omitted or `nil`. In this case,
217
+ # the comparison is between the index and the working tree; the stats reflect
218
+ # unstaged changes.
219
+ #
220
+ # @example Get working tree stats since HEAD
221
+ # stats = repo.diff_stats
222
+ # stats.insertions #=> 3
223
+ # stats.deletions #=> 1
224
+ #
225
+ # @example Compare two specific commits
226
+ # repo.diff_stats('abc1234', 'def5678')
227
+ #
228
+ # @example Get unstaged stats (index vs. working tree)
229
+ # repo.diff_stats(nil).insertions
230
+ #
231
+ # @example Limit stats to a sub-path
232
+ # repo.diff_stats('HEAD~1', 'HEAD', path_limiter: 'lib/')
233
+ #
234
+ # @param obj1 [String, nil] the first commit or object to compare; defaults to
235
+ # `'HEAD'`
236
+ #
237
+ # @param obj2 [String, nil] the second commit or object to compare
238
+ #
239
+ # @param opts [Hash] options to filter the diff
240
+ #
241
+ # @option opts [String, Pathname, Array<String, Pathname>, nil] :path_limiter (nil)
242
+ # limit the stats to the given path(s)
243
+ #
244
+ # @return [Git::DiffStats] a lazy stats object for the comparison
245
+ #
246
+ # @raise [ArgumentError] if unsupported options are provided
247
+ #
248
+ # @raise [ArgumentError] if `obj1` is `nil` but `obj2` is not OR if `obj1` or `obj2` starts with `"-"`
249
+ #
250
+ # @see #diff_numstat
251
+ #
252
+ # @see https://git-scm.com/docs/git-diff git-diff documentation
253
+ #
254
+ def diff_stats(obj1 = 'HEAD', obj2 = nil, opts = {})
255
+ SharedPrivate.assert_valid_opts!(DIFF_STATS_ALLOWED_OPTS, **opts)
256
+ raise ArgumentError, 'Invalid arguments: obj1 is nil but obj2 is not' if obj1.nil? && !obj2.nil?
257
+
258
+ Git::DiffStats.new(self, obj1, obj2, opts[:path_limiter])
259
+ end
260
+
261
+ # Returns a lazy {Git::Diff} object for the comparison between two trees
262
+ #
263
+ # Compares (1) two commits, (2) a commit against the working tree, or (3) the
264
+ # index against the working tree. The returned {Git::Diff} is lazy — it does
265
+ # not run any git commands until an accessor method (e.g., {Git::Diff#patch},
266
+ # {Git::Diff#each}) is called.
267
+ #
268
+ # Use {Git::Diff#path} to limit the diff to a sub-path after construction.
269
+ #
270
+ # @example Get the diff since HEAD
271
+ # diff = repo.diff
272
+ # diff.patch #=> "diff --git a/lib/foo.rb ..."
273
+ #
274
+ # @example Compare two specific commits
275
+ # repo.diff('abc1234', 'def5678').patch
276
+ #
277
+ # @example Limit to a sub-path
278
+ # repo.diff('HEAD~1', 'HEAD').path('lib/').patch
279
+ #
280
+ # @example Get unstaged changes (index vs. working tree)
281
+ # repo.diff(nil).patch
282
+ #
283
+ # @param obj1 [String, nil] the first commit or object to compare; defaults to
284
+ # `'HEAD'`
285
+ #
286
+ # @param obj2 [String, nil] the second commit or object to compare
287
+ #
288
+ # @return [Git::Diff] a lazy diff object for the comparison
289
+ #
290
+ # @see https://git-scm.com/docs/git-diff git-diff documentation
291
+ #
292
+ def diff(obj1 = 'HEAD', obj2 = nil)
293
+ Git::Diff.new(self, obj1, obj2)
294
+ end
295
+
296
+ # Option keys accepted by {#diff_path_status}
297
+ #
298
+ # @return [Array<Symbol>]
299
+ #
300
+ # @api private
301
+ #
302
+ DIFF_PATH_STATUS_ALLOWED_OPTS = %i[path_limiter].freeze
303
+ private_constant :DIFF_PATH_STATUS_ALLOWED_OPTS
304
+
305
+ # Returns the file path status between two trees
306
+ #
307
+ # Compares (1) two commits, (2) a commit against the working tree, or (3) the
308
+ # index against the working tree and returns a {Git::DiffPathStatus} enumerating
309
+ # each changed file together with its status code (e.g. `"M"` for modified,
310
+ # `"A"` for added, `"D"` for deleted, `"R100"` for a rename with 100%
311
+ # similarity, etc.).
312
+ #
313
+ # **Comparing two commits**
314
+ #
315
+ # When both from and to are provided, the comparison is between those two
316
+ # refs (commits, tags, branches, etc.).
317
+ #
318
+ # **Comparing a commit against the working tree**
319
+ #
320
+ # When only from is provided (and isn't nil), the comparison is between from and
321
+ # the working tree; the status reflects all changes since from.
322
+ #
323
+ # **Comparing the index against the working tree**
324
+ #
325
+ # When from is explicitly `nil` then to must be omitted or `nil`. In this case,
326
+ # the comparison is between the index and the working tree; the status reflects
327
+ # unstaged changes.
328
+ #
329
+ # @example Get working tree path changes since HEAD
330
+ # repo.diff_path_status #=> #<Git::DiffPathStatus ...>
331
+ # repo.diff_path_status.to_h #=> { "README.md" => "M", "lib/foo.rb" => "A" }
332
+ #
333
+ # @example Compare two specific commits
334
+ # repo.diff_path_status('abc1234', 'def5678').to_h
335
+ #
336
+ # @example Get unstaged path changes (index vs. working tree)
337
+ # repo.diff_path_status(nil).to_h
338
+ #
339
+ # @example Limit the comparison to a sub-path
340
+ # repo.diff_path_status('HEAD~1', 'HEAD', path_limiter: 'lib/')
341
+ #
342
+ # @param from [String, nil] the first commit or object to compare; defaults to
343
+ # `'HEAD'`
344
+ #
345
+ # @param to [String, nil] the second commit or object to compare
346
+ #
347
+ # @param opts [Hash] options to filter the diff
348
+ #
349
+ # @option opts [String, Pathname, Array<String, Pathname>, nil] :path_limiter (nil)
350
+ # limit the status report to the given path(s)
351
+ #
352
+ # @return [Git::DiffPathStatus] the name-status report for the comparison
353
+ #
354
+ # @raise [ArgumentError] if unsupported options are provided
355
+ #
356
+ # @raise [ArgumentError] if `from` is `nil` but `to` is not OR if `from` or `to` starts with `"-"`
357
+ #
358
+ # @raise [Git::FailedError] if git exits outside the allowed range (exit code > 2)
359
+ #
360
+ # @see https://git-scm.com/docs/git-diff git-diff documentation
361
+ #
362
+ def diff_path_status(from = 'HEAD', to = nil, opts = {})
363
+ SharedPrivate.assert_valid_opts!(DIFF_PATH_STATUS_ALLOWED_OPTS, **opts)
364
+ raise ArgumentError, 'Invalid arguments: `from` is nil but `to` is not' if from.nil? && !to.nil?
365
+
366
+ pathspecs = Private.normalize_pathspecs(opts[:path_limiter], 'path limiter')
367
+
368
+ result = Private.call_diff_command(@execution_context, from, to, pathspecs)
369
+ Git::DiffPathStatus.new(Private.extract_name_status_from_raw(result.stdout))
370
+ end
371
+
372
+ # Compares the index and the working directory
373
+ #
374
+ # Runs `git diff-files` to list files that differ between the index
375
+ # (staging area) and the working directory. These are changes that have
376
+ # been made to tracked files but not yet staged.
377
+ #
378
+ # @example List all files with unstaged changes
379
+ # repo.diff_files
380
+ # #=> {
381
+ # # "lib/foo.rb" => {
382
+ # # mode_index: "100644", mode_repo: "100644",
383
+ # # path: "lib/foo.rb", sha_repo: "abc1234",
384
+ # # sha_index: "0000000000000000000000000000000000000000",
385
+ # # type: "M"
386
+ # # }
387
+ # # }
388
+ #
389
+ # @return [Hash{String => Hash}] a hash keyed by file path
390
+ #
391
+ # Each value is a hash with the following keys (note the legacy naming
392
+ # where `:*_repo` holds index data and `:*_index` holds working tree data):
393
+ #
394
+ # * `:mode_index` [String] the working tree file mode (legacy name)
395
+ # * `:mode_repo` [String] the index (staging area) file mode (legacy name)
396
+ # * `:path` [String] the file path
397
+ # * `:sha_repo` [String] the SHA of the object in the index (staging area) (legacy name)
398
+ # * `:sha_index` [String] the SHA of the object in the working tree; all
399
+ # zeros when git has not computed the working tree blob SHA (legacy name)
400
+ # * `:type` [String] the status code (e.g. `"M"`, `"A"`, `"D"`)
401
+ #
402
+ # @raise [Git::FailedError] if git exits outside the allowed range (exit code > 1)
403
+ #
404
+ # @note The field names in the returned hash are **legacy names** inherited
405
+ # from `Git::Lib#diff_files` and appear counterintuitive: `:mode_repo`
406
+ # and `:sha_repo` hold **index (staging area)** values, while
407
+ # `:mode_index` and `:sha_index` hold **working tree** values.
408
+ #
409
+ # @see https://git-scm.com/docs/git-diff-files git-diff-files documentation
410
+ #
411
+ def diff_files
412
+ Git::Commands::Status.new(@execution_context).call
413
+ Private.parse_diff_files_output(
414
+ Git::Commands::DiffFiles.new(@execution_context).call.stdout
415
+ )
416
+ end
417
+
418
+ # Compares the working tree against the given tree object
419
+ #
420
+ # Runs `git diff-index <treeish>` (without `--cached`) to list files that
421
+ # differ between the given tree object (e.g. a commit or `"HEAD"`) and the
422
+ # working tree. The index is refreshed via `git status` first so that cached
423
+ # stat information is up to date.
424
+ #
425
+ # This is equivalent to the 4.x `Git::Lib#diff_index` behavior, which also
426
+ # ran `git diff-index` without `--cached`.
427
+ #
428
+ # @example List all working-tree files that differ from HEAD
429
+ # repo.diff_index('HEAD')
430
+ # #=> {
431
+ # # "lib/foo.rb" => {
432
+ # # mode_index: "100644", mode_repo: "100644",
433
+ # # path: "lib/foo.rb", sha_repo: "abc1234",
434
+ # # sha_index: "0000000000000000000000000000000000000000",
435
+ # # type: "M"
436
+ # # }
437
+ # # }
438
+ #
439
+ # @param treeish [String] the tree object to compare against (e.g. `'HEAD'`,
440
+ # a commit SHA, or a tag name)
441
+ #
442
+ # @return [Hash{String => Hash}] a hash keyed by file path
443
+ #
444
+ # Each value is a hash with the following keys (note the legacy naming
445
+ # where `:*_repo` holds tree data and `:*_index` holds working tree data):
446
+ #
447
+ # * `:mode_index` [String] the working tree file mode (legacy name)
448
+ # * `:mode_repo` [String] the tree (treeish) file mode (legacy name)
449
+ # * `:path` [String] the file path
450
+ # * `:sha_repo` [String] the SHA of the object in the tree (treeish) (legacy name)
451
+ # * `:sha_index` [String] the SHA of the object in the working tree; all
452
+ # zeros when git has not yet computed the working tree blob SHA (legacy name)
453
+ # * `:type` [String] the status code (e.g. `"M"`, `"A"`, `"D"`)
454
+ #
455
+ # @raise [Git::FailedError] if git exits outside the allowed range (exit code > 1)
456
+ #
457
+ # @note `git diff-index` without `--cached` uses the index as a stat cache:
458
+ # any file whose index entry differs from the tree is reported as changed,
459
+ # even when the on-disk working-tree content is byte-for-byte identical to
460
+ # the tree. A staged change that has been reverted in the working tree will
461
+ # therefore still appear in the result (because the index still differs from
462
+ # the tree).
463
+ #
464
+ # @note The field names in the returned hash are **legacy names** inherited
465
+ # from `Git::Lib#diff_index` and appear counterintuitive: `:mode_repo`
466
+ # and `:sha_repo` hold **tree (treeish)** values, while `:mode_index` and
467
+ # `:sha_index` hold **working tree** values.
468
+ #
469
+ # @see https://git-scm.com/docs/git-diff-index git-diff-index documentation
470
+ #
471
+ def diff_index(treeish)
472
+ Git::Commands::Status.new(@execution_context).call
473
+ Private.parse_diff_files_output(
474
+ Git::Commands::DiffIndex.new(@execution_context).call(treeish).stdout
475
+ )
476
+ end
477
+
478
+ # Private helpers local to {Git::Repository::Diffing}
479
+ #
480
+ # @api private
481
+ #
482
+ module Private
483
+ module_function
484
+
485
+ # Extracts only the patch text from combined diff command output
486
+ #
487
+ # When {Git::Commands::Diff} is called with `patch: true, numstat: true,
488
+ # shortstat: true`, the stdout contains numstat lines, a shortstat summary
489
+ # line, and then the unified patch text starting at `"diff --git "`. This
490
+ # method strips the leading numstat/shortstat lines and returns only the
491
+ # patch portion.
492
+ #
493
+ # @param output [String] combined command output
494
+ #
495
+ # @return [String] only the patch text (may be empty when there are no
496
+ # changes)
497
+ #
498
+ def extract_patch_text(output)
499
+ match = output.match(/^diff --git /m)
500
+ match ? output[match.begin(0)..] : output
501
+ end
502
+
503
+ # Runs git-diff with `--raw` format options and returns the result
504
+ #
505
+ # @param execution_context [Git::ExecutionContext] the execution context
506
+ # used to run git commands
507
+ #
508
+ # @param from [String] first ref
509
+ #
510
+ # @param to [String, nil] second ref
511
+ #
512
+ # @param pathspecs [Array<String>, nil] path limiters
513
+ #
514
+ # @return [Git::CommandLine::Result] the result of calling `git diff`
515
+ #
516
+ def call_diff_command(execution_context, from, to, pathspecs)
517
+ Git::Commands::Diff.new(execution_context).call(
518
+ *[from, to].compact,
519
+ raw: true, numstat: true, shortstat: true,
520
+ src_prefix: 'a/', dst_prefix: 'b/',
521
+ path: pathspecs
522
+ )
523
+ end
524
+
525
+ # Normalizes path specifications for Git commands
526
+ #
527
+ # @param pathspecs [String, Pathname, Array<String, Pathname>, nil]
528
+ # the path(s) to normalize
529
+ #
530
+ # @param arg_name [String] the argument name used in error messages
531
+ #
532
+ # @return [Array<String>, nil] the normalized paths, or `nil` if none are valid
533
+ #
534
+ # @raise [ArgumentError] if any path is not a `String` or `Pathname`
535
+ #
536
+ def normalize_pathspecs(pathspecs, arg_name)
537
+ return nil unless pathspecs
538
+
539
+ normalized = Array(pathspecs)
540
+ validate_pathspec_types(normalized, arg_name)
541
+
542
+ normalized = normalized.map(&:to_s).reject(&:empty?)
543
+ return nil if normalized.empty?
544
+
545
+ normalized
546
+ end
547
+
548
+ # Raises an error if any element of `pathspecs` is not a `String` or `Pathname`
549
+ #
550
+ # @param pathspecs [Array] the path elements to validate
551
+ #
552
+ # @param arg_name [String] the argument name used in error messages
553
+ #
554
+ # @return [void]
555
+ #
556
+ # @raise [ArgumentError] if any element is not a `String` or `Pathname`
557
+ #
558
+ def validate_pathspec_types(pathspecs, arg_name)
559
+ return if pathspecs.all? { |p| p.is_a?(String) || p.is_a?(Pathname) }
560
+
561
+ raise ArgumentError, "Invalid #{arg_name}: must be a String, Pathname, or Array of Strings/Pathnames"
562
+ end
563
+
564
+ # Parses raw `git diff-files` output into a file-keyed hash
565
+ #
566
+ # Each output line has the format:
567
+ # `:old_mode new_mode old_sha new_sha status\tpath`
568
+ #
569
+ # The leading colon on `old_mode` is stripped when building
570
+ # the `:mode_repo` value.
571
+ #
572
+ # @param stdout [String] raw stdout from {Git::Commands::DiffFiles#call}
573
+ #
574
+ # @return [Hash{String => Hash}] a hash keyed by file path where each
575
+ # value has keys `:mode_index`, `:mode_repo`, `:path`, `:sha_repo`,
576
+ # `:sha_index`, and `:type`
577
+ #
578
+ def parse_diff_files_output(stdout)
579
+ stdout.split("\n").each_with_object({}) do |line, memo|
580
+ next if line.empty?
581
+
582
+ tab_pos = line.index("\t")
583
+ next unless tab_pos
584
+
585
+ path, entry = parse_diff_files_line(line, tab_pos)
586
+ memo[path] = entry
587
+ end
588
+ end
589
+
590
+ # Parses a single raw `git diff-files` output line into a path/entry pair
591
+ #
592
+ # @param line [String] a single non-empty line containing a tab character
593
+ #
594
+ # @param tab_pos [Integer] the index of the first tab in the line
595
+ #
596
+ # @return [Array(String, Hash)] two-element array of `[path, entry_hash]`
597
+ #
598
+ def parse_diff_files_line(line, tab_pos)
599
+ path = unescape_quoted_path(line[(tab_pos + 1)..])
600
+ parts = line[0, tab_pos].split
601
+ [path, build_diff_files_entry(path, parts)]
602
+ end
603
+
604
+ # Builds a single file-info hash for {#parse_diff_files_output}
605
+ #
606
+ # @param path [String] the file path
607
+ #
608
+ # @param parts [Array<String>] the whitespace-split fields from the info
609
+ # portion of the diff-files line: `[mode_src, mode_dest, sha_src,
610
+ # sha_dest, type]`
611
+ #
612
+ # @return [Hash] entry hash with keys `:mode_index`, `:mode_repo`, `:path`,
613
+ # `:sha_repo`, `:sha_index`, `:type`
614
+ #
615
+ def build_diff_files_entry(path, parts)
616
+ {
617
+ mode_index: parts[1],
618
+ mode_repo: parts[0].to_s[1, 7],
619
+ path: path,
620
+ sha_repo: parts[2],
621
+ sha_index: parts[3],
622
+ type: parts[4]
623
+ }
624
+ end
625
+
626
+ # Extracts name-status data from `--raw` diff output lines
627
+ #
628
+ # Raw lines have the format:
629
+ # :old_mode new_mode old_sha new_sha status\tpath
630
+ # or for renames/copies:
631
+ # :old_mode new_mode old_sha new_sha Rxx\told_path\tnew_path
632
+ #
633
+ # @param output [String] raw diff output
634
+ #
635
+ # @return [Hash{String => String}] mapping of file paths to status tokens
636
+ #
637
+ def extract_name_status_from_raw(output)
638
+ output.split("\n").each_with_object({}) do |line, memo|
639
+ next unless line.start_with?(':')
640
+
641
+ parts = line[1..].split(/\s+/, 5)
642
+ status_and_paths = parts[4].split("\t")
643
+ status = status_and_paths[0]
644
+ path = status_and_paths.length > 2 ? status_and_paths[2] : status_and_paths[1]
645
+ memo[unescape_quoted_path(path)] = status
646
+ end
647
+ end
648
+
649
+ # Parses combined `--numstat --shortstat` output into an insertions/deletions hash
650
+ #
651
+ # Strips the trailing shortstat summary line and empty lines, parses the
652
+ # remaining numstat lines, and returns a structured hash with per-file
653
+ # stats and aggregated totals.
654
+ #
655
+ # @param output [String] raw stdout from `git diff --numstat --shortstat`
656
+ #
657
+ # @return [Hash] per-file insertion and deletion counts plus aggregate totals
658
+ #
659
+ # ```
660
+ # {
661
+ # total: { insertions: Integer, deletions: Integer, lines: Integer, files: Integer },
662
+ # files: { "path/to/file" => { insertions: Integer, deletions: Integer } }
663
+ # }
664
+ # ```
665
+ #
666
+ def parse_numstat_output(output)
667
+ file_stats = extract_numstat_lines(output).map { |line| parse_numstat_line(line) }
668
+ { total: build_numstat_totals(file_stats), files: build_numstat_files(file_stats) }
669
+ end
670
+
671
+ # Builds the `:total` sub-hash for {#parse_numstat_output}
672
+ #
673
+ # @param file_stats [Array<Hash>] per-file stats from {#parse_numstat_line}
674
+ #
675
+ # @return [Hash] aggregate totals
676
+ #
677
+ # `{ insertions: Integer, deletions: Integer, lines: Integer, files: Integer }`
678
+ #
679
+ def build_numstat_totals(file_stats)
680
+ insertions = file_stats.sum { |s| s[:insertions] }
681
+ deletions = file_stats.sum { |s| s[:deletions] }
682
+ { insertions: insertions, deletions: deletions,
683
+ lines: insertions + deletions, files: file_stats.size }
684
+ end
685
+
686
+ # Builds the `:files` sub-hash for {#parse_numstat_output}
687
+ #
688
+ # @param file_stats [Array<Hash>] per-file stats from {#parse_numstat_line}
689
+ #
690
+ # @return [Hash{String => Hash}] per-file insertion and deletion counts
691
+ #
692
+ def build_numstat_files(file_stats)
693
+ file_stats.to_h { |s| [s[:filename], s.slice(:insertions, :deletions)] }
694
+ end
695
+
696
+ # Filters raw numstat+shortstat output to only the numstat lines
697
+ #
698
+ # @param output [String] combined command output
699
+ #
700
+ # @return [Array<String>] only the numstat lines (no empties, no shortstat line)
701
+ #
702
+ def extract_numstat_lines(output)
703
+ output.split("\n").reject { |l| l.empty? || l.match?(/^\s*\d+\s+files?\s+changed/) }
704
+ end
705
+
706
+ # Parses a single `--numstat` line into a stats hash
707
+ #
708
+ # Numstat lines have the format `<insertions>\t<deletions>\t<path>`.
709
+ # Quoted paths (containing non-ASCII or special characters) are unescaped.
710
+ #
711
+ # @param line [String] a single numstat output line
712
+ #
713
+ # @return [Hash] `{ filename: String, insertions: Integer, deletions: Integer }`
714
+ #
715
+ def parse_numstat_line(line)
716
+ insertions_s, deletions_s, filename = line.split("\t", 3)
717
+ { filename: unescape_quoted_path(filename), insertions: insertions_s.to_i, deletions: deletions_s.to_i }
718
+ end
719
+
720
+ # Unescapes a git-quoted path (e.g. `"quoted_file_\\342\\230\\240"`)
721
+ #
722
+ # Git quotes paths that contain non-ASCII or special characters by
723
+ # wrapping them in double-quotes and octal-escaping each byte. This
724
+ # method strips the surrounding quotes and delegates unescaping to
725
+ # {Git::EscapedPath}.
726
+ #
727
+ # @param path [String] the path as it appears in git output
728
+ #
729
+ # @return [String] the unescaped path
730
+ #
731
+ def unescape_quoted_path(path)
732
+ if path.start_with?('"') && path.end_with?('"')
733
+ Git::EscapedPath.new(path[1..-2]).unescape
734
+ else
735
+ path
736
+ end
737
+ end
738
+ end
739
+
740
+ private_constant :Private
741
+ end
742
+ end
743
+ end