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
data/lib/git/path.rb DELETED
@@ -1,38 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Git
4
- # A base class that represents and validates a filesystem path
5
- #
6
- # Use for tracking things relevant to a Git repository, such as the working
7
- # directory or index file.
8
- #
9
- class Path
10
- def path
11
- Git::Deprecation.warn(
12
- 'The .path accessor is deprecated and will be removed in v5.0. ' \
13
- 'Use .to_s instead.'
14
- )
15
- @path
16
- end
17
-
18
- def initialize(path, must_exist: true)
19
- path = File.expand_path(path)
20
-
21
- raise ArgumentError, 'path does not exist', [path] if must_exist && !File.exist?(path)
22
-
23
- @path = path
24
- end
25
-
26
- def readable?
27
- File.readable?(@path)
28
- end
29
-
30
- def writable?
31
- File.writable?(@path)
32
- end
33
-
34
- def to_s
35
- @path
36
- end
37
- end
38
- end
data/lib/git/remote.rb DELETED
@@ -1,39 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Git
4
- # A remote in a Git repository
5
- class Remote
6
- attr_accessor :name, :url, :fetch_opts
7
-
8
- def initialize(base, name)
9
- @base = base
10
- config = @base.lib.config_remote(name)
11
- @name = name
12
- @url = config['url']
13
- @fetch_opts = config['fetch']
14
- end
15
-
16
- def fetch(opts = {})
17
- @base.fetch(@name, opts)
18
- end
19
-
20
- # merge this remote locally
21
- def merge(branch = @base.current_branch)
22
- remote_tracking_branch = "#{@name}/#{branch}"
23
- @base.merge(remote_tracking_branch)
24
- end
25
-
26
- def branch(branch = @base.current_branch)
27
- remote_tracking_branch = "#{@name}/#{branch}"
28
- Git::Branch.new(@base, remote_tracking_branch)
29
- end
30
-
31
- def remove
32
- @base.lib.remote_remove(@name)
33
- end
34
-
35
- def to_s
36
- @name
37
- end
38
- end
39
- end
data/lib/git/stash.rb DELETED
@@ -1,26 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Git
4
- # A stash in a Git repository
5
- class Stash
6
- def initialize(base, message, save: false)
7
- @base = base
8
- @message = message
9
- self.save unless save
10
- end
11
-
12
- def save
13
- @saved = @base.lib.stash_save(@message)
14
- end
15
-
16
- def saved?
17
- @saved
18
- end
19
-
20
- attr_reader :message
21
-
22
- def to_s
23
- message
24
- end
25
- end
26
- end
data/lib/git/stashes.rb DELETED
@@ -1,56 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Git
4
- # object that holds all the available stashes
5
- class Stashes
6
- include Enumerable
7
-
8
- def initialize(base)
9
- @stashes = []
10
-
11
- @base = base
12
-
13
- @base.lib.stashes_all.each do |indexed_message|
14
- _index, message = indexed_message
15
- @stashes.unshift(Git::Stash.new(@base, message, save: true))
16
- end
17
- end
18
-
19
- #
20
- # Returns an multi-dimensional Array of elements that have been stash saved.
21
- # Array is based on position and name. See Example
22
- #
23
- # @example Returns Array of items that have been stashed
24
- # .all - [0, "testing-stash-all"]]
25
- # @return [Array]
26
- def all
27
- @base.lib.stashes_all
28
- end
29
-
30
- def save(message)
31
- s = Git::Stash.new(@base, message)
32
- @stashes.unshift(s) if s.saved?
33
- end
34
-
35
- def apply(index = nil)
36
- @base.lib.stash_apply(index)
37
- end
38
-
39
- def clear
40
- @base.lib.stash_clear
41
- @stashes = []
42
- end
43
-
44
- def size
45
- @stashes.size
46
- end
47
-
48
- def each(&)
49
- @stashes.each(&)
50
- end
51
-
52
- def [](index)
53
- @stashes[index.to_i]
54
- end
55
- end
56
- end
data/lib/git/status.rb DELETED
@@ -1,159 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Git
4
- # The Status class gets the status of a git repository. It identifies which
5
- # files have been modified, added, or deleted, including untracked files.
6
- # The Status object is an Enumerable of StatusFile objects.
7
- #
8
- # @api public
9
- #
10
- class Status
11
- include Enumerable
12
-
13
- # @param base [Git::Base] The base git object
14
- def initialize(base)
15
- @base = base
16
- # The factory returns a hash of file paths to StatusFile objects.
17
- @files = StatusFileFactory.new(base).construct_files
18
- end
19
-
20
- # File status collections, memoized for performance.
21
- def changed = @changed ||= select_files { |f| f.type == 'M' }
22
- def added = @added ||= select_files { |f| f.type == 'A' }
23
- def deleted = @deleted ||= select_files { |f| f.type == 'D' }
24
- # This works with `true` or `nil`
25
- def untracked = @untracked ||= select_files(&:untracked)
26
-
27
- # Predicate methods to check the status of a specific file.
28
- def changed?(file) = file_in_collection?(:changed, file)
29
- def added?(file) = file_in_collection?(:added, file)
30
- def deleted?(file) = file_in_collection?(:deleted, file)
31
- def untracked?(file) = file_in_collection?(:untracked, file)
32
-
33
- # Access a status file by path, or iterate over all status files.
34
- def [](file) = @files[file]
35
- def each(&) = @files.values.each(&)
36
-
37
- # Returns a formatted string representation of the status.
38
- def pretty
39
- map { |file| pretty_file(file) }.join << "\n"
40
- end
41
-
42
- private
43
-
44
- def pretty_file(file)
45
- <<~FILE
46
- #{file.path}
47
- \tsha(r) #{file.sha_repo} #{file.mode_repo}
48
- \tsha(i) #{file.sha_index} #{file.mode_index}
49
- \ttype #{file.type}
50
- \tstage #{file.stage}
51
- \tuntrac #{file.untracked}
52
- FILE
53
- end
54
-
55
- def select_files(&block)
56
- @files.select { |_path, file| block.call(file) }
57
- end
58
-
59
- def file_in_collection?(collection_name, file_path)
60
- collection = public_send(collection_name)
61
- if ignore_case?
62
- downcased_keys(collection_name).include?(file_path.downcase)
63
- else
64
- collection.key?(file_path)
65
- end
66
- end
67
-
68
- def downcased_keys(collection_name)
69
- @_downcased_keys ||= {}
70
- @_downcased_keys[collection_name] ||=
71
- public_send(collection_name).keys.to_set(&:downcase)
72
- end
73
-
74
- def ignore_case?
75
- return @_ignore_case if defined?(@_ignore_case)
76
-
77
- @_ignore_case = (@base.config('core.ignoreCase') == 'true')
78
- rescue Git::FailedError
79
- @_ignore_case = false
80
- end
81
-
82
- # Represents a single file's status in the git repository. Each instance
83
- # holds information about a file's state in the index and working tree.
84
- class StatusFile
85
- attr_reader :path, :type, :stage, :mode_index, :mode_repo,
86
- :sha_index, :sha_repo, :untracked
87
-
88
- def initialize(base, hash)
89
- @base = base
90
- @path = hash[:path]
91
- @type = hash[:type]
92
- @stage = hash[:stage]
93
- @mode_index = hash[:mode_index]
94
- @mode_repo = hash[:mode_repo]
95
- @sha_index = hash[:sha_index]
96
- @sha_repo = hash[:sha_repo]
97
- @untracked = hash[:untracked]
98
- end
99
-
100
- # Returns a Git::Object::Blob for either the index or repo version of the file.
101
- def blob(type = :index)
102
- sha = type == :repo ? sha_repo : (sha_index || sha_repo)
103
- @base.object(sha) if sha
104
- end
105
- end
106
-
107
- # A factory class responsible for fetching git status data and building
108
- # a hash of StatusFile objects.
109
- # @api private
110
- class StatusFileFactory
111
- def initialize(base)
112
- @base = base
113
- @lib = base.lib
114
- end
115
-
116
- # Gathers all status data and builds a hash of file paths to
117
- # StatusFile objects.
118
- def construct_files
119
- files_data = fetch_all_files_data
120
- files_data.transform_values do |data|
121
- StatusFile.new(@base, data)
122
- end
123
- end
124
-
125
- private
126
-
127
- # Fetches and merges status information from multiple git commands.
128
- def fetch_all_files_data
129
- files = @lib.ls_files # Start with files tracked in the index.
130
- merge_untracked_files(files)
131
- merge_modified_files(files)
132
- merge_head_diffs(files)
133
- files
134
- end
135
-
136
- def merge_untracked_files(files)
137
- @lib.untracked_files.each do |file|
138
- files[file] = { path: file, untracked: true }
139
- end
140
- end
141
-
142
- def merge_modified_files(files)
143
- # Merge changes between the index and the working directory.
144
- @lib.diff_files.each do |path, data|
145
- (files[path] ||= {}).merge!(data)
146
- end
147
- end
148
-
149
- def merge_head_diffs(files)
150
- return if @lib.empty?
151
-
152
- # Merge changes between HEAD and the index.
153
- @lib.diff_index('HEAD').each do |path, data|
154
- (files[path] ||= {}).merge!(data)
155
- end
156
- end
157
- end
158
- end
159
- end
@@ -1,6 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Git
4
- class WorkingDirectory < Git::Path
5
- end
6
- end
data/lib/git/worktree.rb DELETED
@@ -1,39 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'git/path'
4
-
5
- module Git
6
- # A worktree in a Git repository
7
- class Worktree
8
- attr_accessor :full, :dir
9
-
10
- def initialize(base, dir, gcommit = nil)
11
- @full = dir
12
- @full += " #{gcommit}" unless gcommit.nil?
13
- @base = base
14
- @dir = dir
15
- @gcommit = gcommit
16
- end
17
-
18
- def gcommit
19
- @gcommit ||= @base.gcommit(@full)
20
- @gcommit
21
- end
22
-
23
- def add
24
- @base.lib.worktree_add(@dir, @gcommit)
25
- end
26
-
27
- def remove
28
- @base.lib.worktree_remove(@dir)
29
- end
30
-
31
- def to_a
32
- [@full]
33
- end
34
-
35
- def to_s
36
- @full
37
- end
38
- end
39
- end
data/lib/git/worktrees.rb DELETED
@@ -1,47 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Git
4
- # object that holds all the available worktrees
5
- class Worktrees
6
- include Enumerable
7
-
8
- def initialize(base)
9
- @worktrees = {}
10
-
11
- @base = base
12
-
13
- # Array contains [dir, git_hash]
14
- @base.lib.worktrees_all.each do |w|
15
- @worktrees[w[0]] = Git::Worktree.new(@base, w[0], w[1])
16
- end
17
- end
18
-
19
- # array like methods
20
-
21
- def size
22
- @worktrees.size
23
- end
24
-
25
- def each(&)
26
- @worktrees.values.each(&)
27
- end
28
-
29
- def [](worktree_name)
30
- @worktrees.values.each_with_object(@worktrees) do |worktree, worktrees|
31
- worktrees[worktree.full] ||= worktree
32
- end[worktree_name.to_s]
33
- end
34
-
35
- def to_s
36
- out = ''
37
- @worktrees.each_value do |b|
38
- out << b.to_s << "\n"
39
- end
40
- out
41
- end
42
-
43
- def prune
44
- @base.lib.worktree_prune
45
- end
46
- end
47
- end
data/package.json DELETED
@@ -1,10 +0,0 @@
1
- {
2
- "devDependencies": {
3
- "@commitlint/cli": "^19.8.0",
4
- "@commitlint/config-conventional": "^19.8.0",
5
- "husky": "^9.1.7"
6
- },
7
- "scripts": {
8
- "prepare": "husky"
9
- }
10
- }
@@ -1,66 +0,0 @@
1
- # Analysis of the Current Git Gem Architecture and Its Challenges
2
-
3
- This document provides an in-depth look at the current architecture of the `git` gem, outlining its primary components and the design challenges that have emerged over time. Understanding these challenges is the key motivation for the proposed architectural redesign.
4
-
5
- - [1. Overview of the Current Architecture](#1-overview-of-the-current-architecture)
6
- - [2. Key Architectural Challenges](#2-key-architectural-challenges)
7
- - [A. Unclear Separation of Concerns](#a-unclear-separation-of-concerns)
8
- - [B. Circular Dependency](#b-circular-dependency)
9
- - [C. Undefined Public API Boundary](#c-undefined-public-api-boundary)
10
- - [D. Slow and Brittle Test Suite](#d-slow-and-brittle-test-suite)
11
-
12
- ## 1. Overview of the Current Architecture
13
-
14
- The gem's current design is centered around three main classes: `Git`, `Git::Base`, and `Git::Lib`.
15
-
16
- - **`Git` (Top-Level Module)**: This module serves as the primary public entry point for creating repository objects. It contains class-level factory methods like `Git.open`, `Git.clone`, and `Git.init`. It also provides an interface for accessing global git configuration settings.
17
-
18
- **`Git::Base`**: This is the main object that users interact with after creating or opening a repository. It holds the high-level public API for most git operations (e.g., `g.commit`, `g.add`, `g.status`). It is responsible for managing the repository's state, such as the paths to the working directory and the `.git` directory.
19
-
20
- **`Git::Lib`**: This class is intended to be the low-level wrapper around the `git` command-line tool. It contains the methods that build the specific command-line arguments and execute the `git` binary. In practice, it also contains a significant amount of logic for parsing the output of these commands.
21
-
22
- ## 2. Key Architectural Challenges
23
-
24
- While this structure has been functional, several significant design challenges make the codebase difficult to maintain, test, and evolve.
25
-
26
- ### A. Unclear Separation of Concerns
27
-
28
- The responsibilities between Git::Base and Git::Lib are "muddy" and overlap significantly.
29
-
30
- - `Git::Base` sometimes contains logic that feels like it should be lower-level.
31
-
32
- - `Git::Lib`, which should ideally only be concerned with command execution, is filled with high-level logic for parsing command output into specific Ruby objects (e.g., parsing log output, diff stats, and branch lists).
33
-
34
- This blending of responsibilities makes it hard to determine where a specific piece of logic should reside, leading to an inconsistent and confusing internal structure.
35
-
36
- ### B. Circular Dependency
37
-
38
- This is the most critical architectural flaw in the current design.
39
-
40
- - A `Git::Base` instance is created.
41
-
42
- - The first time a command is run, `Git::Base` lazily initializes a `Git::Lib` instance via its `.lib` accessor method.
43
-
44
- - The `Git::Lib` constructor is passed the `Git::Base` instance (`self`) so that it can read the repository's path configuration back from the object that is creating it.
45
-
46
- This creates a tight, circular coupling: `Git::Base` depends on `Git::Lib` to execute commands, but `Git::Lib` depends on `Git::Base` for its own configuration. This pattern makes the classes difficula to instantiate or test in isolation and creates a fragile system where changes in one class can have unexpected side effects in the other.
47
-
48
- ### C. Undefined Public API Boundary
49
-
50
- The gem lacks a formally defined public interface. Because `Git::Base` exposes its internal `Git::Lib` instance via the public `g.lib` accessor, many users have come to rely on `Git::Lib` and its methods as if they were part of the public API.
51
-
52
- This has two negative consequences:
53
-
54
- 1. It prevents the gem's maintainers from refactoring or changing the internal implementation of `Git::Lib` without causing breaking changes for users.
55
-
56
- 2. It exposes complex, internal methods to users, creating a confusing and inconsistent user experience.
57
-
58
- ### D. Slow and Brittle Test Suite
59
-
60
- The current testing strategy, built on `TestUnit`, suffers from two major issues:
61
-
62
- - **Over-reliance on Fixtures**: Most tests depend on having a complete, physical git repository on the filesystem to run against. Managing these fixtures is cumbersome.
63
-
64
- - **Excessive Shelling Out**: Because the logic for command execution and output parsing are tightly coupled, nearly every test must shell out to the actual `git` command-line tool.
65
-
66
- This makes the test suite extremely slow, especially on non-UNIX platforms like Windows where process creation is more expensive. The slow feedback loop discourages frequent testing and makes development more difficult. The brittleness of filesystem-dependent tests also leads to flickering or unreliable test runs.
@@ -1,130 +0,0 @@
1
- # Proposed Redesigned Architecture for the Git Gem
2
-
3
- This document outlines a proposal for a major redesign of the git gem, targeted for version 5.0.0. The goal of this redesign is to modernize the gem's architecture, making it more robust, maintainable, testable, and easier for new contributors to understand.
4
-
5
- - [1. Motivation](#1-motivation)
6
- - [2. The New Architecture: A Three-Layered Approach](#2-the-new-architecture-a-three-layered-approach)
7
- - [3. Key Design Principles](#3-key-design-principles)
8
- - [A. Clear Public vs. Private API](#a-clear-public-vs-private-api)
9
- - [B. Dependency Injection](#b-dependency-injection)
10
- - [C. Immutable Return Values](#c-immutable-return-values)
11
- - [D. Clear Naming for Path Objects](#d-clear-naming-for-path-objects)
12
- - [4. Testing Strategy Overhaul](#4-testing-strategy-overhaul)
13
- - [5. Impact on Users: Breaking Changes for v5.0.0](#5-impact-on-users-breaking-changes-for-v500)
14
-
15
- ## 1. Motivation
16
-
17
- The current architecture, while functional, has several design issues that have accrued over time, making it difficult to extend and maintain.
18
-
19
- - **Unclear Separation of Concerns**: The responsibilities of the `Git`, `Git::Base`, and `Git::Lib` classes are "muddy." `Git::Base` acts as both a high-level API and a factory, while `Git::Lib` contains a mix of low-level command execution and high-level output parsing.
20
-
21
- - **Circular Dependency**: A key architectural flaw is the circular dependency between `Git::Base` and `Git::Lib`. `Git::Base` creates and depends on `Git::Lib`, but `Git::Lib`'s constructor requires an instance of Git::Base to access configuration. This tight coupling makes the classes difficult to reason about and test in isolation.
22
-
23
- - **Undefined Public API**: The boundary between the gem's public API and its internal implementation is not clearly defined. This has led some users to rely on internal classes like `Git::Lib`, making it difficult to refactor the internals without introducing breaking changes.
24
-
25
- - **Slow and Brittle Test Suite**: The current tests rely heavily on filesystem fixtures and shelling out to the git command line for almost every test case. This makes the test suite slow and difficult to maintain, especially on non-UNIX platforms.
26
-
27
- ## 2. The New Architecture: A Three-Layered Approach
28
-
29
- The new design is built on a clear separation of concerns, dividing responsibilities into three distinct layers: a Facade, an Execution Context, and Command Objects.
30
-
31
- 1. The Facade Layer: Git::Repository
32
-
33
- This is the primary public interface that users will interact with.
34
-
35
- **Renaming**: `Git::Base` will be renamed to `Git::Repository`. This name is more descriptive and intuitive.
36
-
37
- **Responsibility**: It will serve as a clean, high-level facade for all common git operations. Its methods will be simple, one-line calls that delegate the actual work to an appropriate command object.
38
-
39
- **Scalability**: To prevent this class from growing too large, its methods will be organized into logical modules (e.g., `Git::Repository::Branching`, `Git::Repository::History`) which are then included in the main class. This keeps the core class definition small and the features well-organized. These categories will be inspired by (but not slavishly follow) the git command line reference in [this page](https://git-scm.com/docs).
40
-
41
- 2. The Execution Layer: Git::ExecutionContext
42
-
43
- This is the low-level, private engine for running commands.
44
-
45
- **Renaming**: `Git::Lib` will be renamed to `Git::ExecutionContext`.
46
-
47
- **Responsibility**: Its sole purpose is to execute raw git commands. It will manage the repository's environment (working directory, .git path, logger) and use the existing `Git::CommandLine` class to interact with the system's git binary. It will have no knowledge of any specific git command's arguments or output.
48
-
49
- 3. The Logic Layer: Git::Commands
50
-
51
- This is where all the command-specific implementation details will live.
52
-
53
- **New Classes**: For each git operation, a new command class will be created within the `Git::Commands` namespace (e.g., `Git::Commands::Commit`, `Git::Commands::Diff`).
54
-
55
- **Dual Responsibility**: Each command class will be responsible for:
56
-
57
- 1. **Building Arguments**: Translating high-level Ruby options into the specific command-line flags and arguments that git expects.
58
-
59
- 2. **Parsing Output**: Taking the raw string output from the ExecutionContext and converting it into rich, structured Ruby objects.
60
-
61
- **Handling Complexity**: For commands with multiple behaviors (like git diff), we can use specialized subclasses (e.g., Git::Commands::Diff::NameStatus, Git::Commands::Diff::Stats) to keep each class focused on a single responsibility.
62
-
63
- ## 3. Key Design Principles
64
-
65
- The new architecture will be guided by the following modern design principles.
66
-
67
- ### A. Clear Public vs. Private API
68
-
69
- A primary goal of this redesign is to establish a crisp boundary between the public API and internal implementation details.
70
-
71
- - **Public Interface**: The public API will consist of the `Git` module (for factories), the `Git::Repository` class, and the specialized data/query objects it returns (e.g., `Git::Log`, `Git::Status`, `Git::Object::Commit`).
72
-
73
- - **Private Implementation**: All other components, including `Git::ExecutionContext` and all classes within the `Git::Commands` namespace, will be considered internal. They will be explicitly marked with the `@api private` YARD tag to discourage external use.
74
-
75
- ### B. Dependency Injection
76
-
77
- The circular dependency will be resolved by implementing a clear, one-way dependency flow.
78
-
79
- 1. The factory methods (`Git.open`, `Git.clone`) will create and configure an instance of `Git::ExecutionContext`.
80
-
81
- 2. This `ExecutionContext` instance will then be injected into the constructor of the `Git::Repository` object.
82
-
83
- This decouples the `Repository` from its execution environment, making the system more modular and easier to test.
84
-
85
- ### C. Immutable Return Values
86
-
87
- To create a more predictable and robust API, methods will return structured, immutable data objects instead of raw strings or hashes.
88
-
89
- This will be implemented using `Data.define` or simple, frozen `Struct`s.
90
-
91
- For example, instead of returning a raw string, `repo.config('user.name')` will return a `Git::Config::Value` object containing the key, value, scope, and source path.
92
-
93
- ### D. Clear Naming for Path Objects
94
-
95
- To improve clarity, all classes that represent filesystem paths will be renamed to follow a consistent `...Path` suffix convention.
96
-
97
- - `Git::WorkingDirectory` -> `Git::WorkingTreePath`
98
-
99
- - `Git::Index` -> `Git::IndexPath`
100
-
101
- - The old `Git::Repository` (representing the .git directory/file) -> `Git::RepositoryPath`
102
-
103
- ## 4. Testing Strategy Overhaul
104
-
105
- The test suite will be modernized to be faster, more reliable, and easier to work with.
106
-
107
- - **Migration to RSpec**: The entire test suite will be migrated from TestUnit to RSpec to leverage its modern tooling and expressive DSL.
108
-
109
- - **Layered Testing**: A three-layered testing strategy will be adopted:
110
-
111
- 1. **Unit Tests**: The majority of tests will be fast, isolated unit tests for the `Command` classes, using mock `ExecutionContexts`.
112
-
113
- 2. **Integration Tests**: A small number of integration tests will verify that `ExecutionContext` correctly interacts with the system's `git` binary.
114
-
115
- 3. **Feature Tests**: A minimal set of high-level tests will ensure the public facade on `Git::Repository` works end-to-end.
116
-
117
- - **Reduced Filesystem Dependency**: This new structure will dramatically reduce the suite's reliance on slow and brittle filesystem fixtures.
118
-
119
- ## 5. Impact on Users: Breaking Changes for v5.0.0
120
-
121
- This redesign is a significant undertaking and will be released as version 5.0.0. It includes several breaking changes that users will need to be aware of when upgrading.
122
-
123
- - **`Git::Lib` is Removed**: Any code directly referencing `Git::Lib` will break.
124
-
125
- - **g.lib Accessor is Removed**: The `.lib` accessor on repository objects will be removed.
126
-
127
- - **Internal Methods Relocated**: Methods that were previously accessible via g.lib will now be private implementation details of the new command classes and will not be directly reachable.
128
-
129
- Users should only rely on the newly defined public interface.
130
-