gitt 4.0.0 → 4.1.0

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: cf995a1e83d2a4b629d45413b6368c0597ee4860bea8116537114a93ee4dfbb4
4
- data.tar.gz: b83e9922914f836999e24aecaa9204aa112e50fd9d8b3a44397b202b3e257ecb
3
+ metadata.gz: 8fbec0bde106e2f9fc5f6a0e24ae9eeeb074fb91302984a3fbc29eccde828499
4
+ data.tar.gz: 56fb1a05bf0a206ad67ce3d6d908b5bb72dfc0d65a9ee90d7552ca8b258663bc
5
5
  SHA512:
6
- metadata.gz: af182dd15da70427375a655da1b74d74bb15fa3980bc954f931b591c84bf6cf0fb87aea892b42f65e70ea22b8680dfef2979ed96430f57b1d27fd20dc2af9954
7
- data.tar.gz: b8f3056ba6fa218c79c663d0536404db6f4dd7d061f8c1b45ee3c67a6cf958e143c665c840b00d86d9e659b46643b74bb41a9ec419891eeff683072de008c597
6
+ metadata.gz: 556cafdb7dfaf50dbc4b2238326e2e3cd7a5f7d145127c3775bca51752bc3afa04bbf13489396d7a3b1d8060e588423c402205b9eb4b7f2a38ff1f11f21df78d
7
+ data.tar.gz: 49ab793068b0447402e43fac302cd881d4b120d18189fa51230fc0b1d90ac11fcafb3838f910a3882c14c98b463deac9f5c72d5a4834516e81f12ff385150d83
checksums.yaml.gz.sig CHANGED
Binary file
data/README.adoc CHANGED
@@ -23,7 +23,7 @@ toc::[]
23
23
 
24
24
  == Features
25
25
 
26
- * Wraps a subset of native {git_link} commands with additional enhancements to improve your working experience.
26
+ * Wraps native {git_link} commands with additional enhancements to improve your working experience.
27
27
  * Answers link:https://dry-rb.org/gems/dry-monads[monads] you can link:https://alchemists.io/articles/ruby_function_composition[pipe] together for more complex workflows.
28
28
  * Provides _optional_ {rspec_link} shared contexts that speed up the testing of your own Git related implementations.
29
29
 
@@ -49,30 +49,34 @@ At a high level, this project provides a centralized Object API via a single obj
49
49
  ----
50
50
  git = Gitt.new
51
51
 
52
- git.branch # Equivalent to `git branch <arguments>`.
53
- git.branch_default # Answers default branch.
54
- git.branch_name # Answers current branch.
55
- git.call # Allows you to run any Git command.
56
- git.commits # Answers enhanced commit records.
57
- git.config # Equivalent to `git config <arguments>`.
58
- git.exist? # Answers if current directory is a Git repository or not.
59
- git.get # Equivalent to `git config get`.
60
- git.inspect # Allows you to inspect the current instance.
61
- git.log # Equivalent to `git log <arguments>`.
62
- git.origin? # Answers if repository has an origin or not.
63
- git.set # Equivalent to `get config set`.
64
- git.tag # Equivalent to `git tag <arguments>`.
65
- git.tags # Answers enhanced tag records.
66
- git.tag? # Answers if local or remote tag exists.
67
- git.tag_create # Create a new tag.
68
- git.tag_last # Answers last tag created.
69
- git.tag_local? # Answers if local tag exists?
70
- git.tag_remote? # Answers if remote tag exists?
71
- git.tag_show # Answers information about a single tag.
72
- git.tagged? # Answers if the repository has any tags.
73
- git.tags_push # Pushes local tags to remote git.
74
- git.uncommitted # Parses `COMMIT_EDITMSG` file and answers the unsaved commit message.
75
- ----
52
+ git.branch # Equivalent to `git branch <arguments>`.
53
+ git.branch_default # Answers default branch.
54
+ git.branch_name # Answers current branch.
55
+ git.call # Allows you to run any Git command.
56
+ git.commits # Answers enhanced commit records.
57
+ git.config # Equivalent to `git config <arguments>`.
58
+ git.exist? # Answers if current directory is a Git repository or not.
59
+ git.get # Equivalent to `git config get`.
60
+ git.inspect # Allows you to inspect the current instance.
61
+ git.log # Equivalent to `git log <arguments>`.
62
+ git.origin? # Answers if repository has an origin or not.
63
+ git.set # Equivalent to `get config set`.
64
+ git.tag # Equivalent to `git tag <arguments>`.
65
+ git.tags # Answers enhanced tag records.
66
+ git.tag? # Answers if local or remote tag exists.
67
+ git.tag_create # Create a new tag.
68
+ git.tag_delete_local # Deletes local tag.
69
+ git.tag_delete_remote # Deletes remote tag.
70
+ git.tag_last # Answers last tag created.
71
+ git.tag_local? # Answers if local tag exists?
72
+ git.tag_remote? # Answers if remote tag exists?
73
+ git.tag_show # Answers information about a single tag.
74
+ git.tagged? # Answers if the repository has any tags.
75
+ git.tags_push # Pushes local tags to remote git.
76
+ git.uncommitted # Parses `COMMIT_EDITMSG` file and answers the unsaved commit message.
77
+ ----
78
+
79
+ 💡 In general, the above (and individual commands below) support link:https://docs.ruby-lang.org/en/master/Process.html#method-c-spawn[Process#spawn] arguments where you can provide environment, command, arguments, and options (hash). Example: `git.tag({"GIT_COMMITTER_DATE" => "2025-01-01 20:00:00"}, "0.0.0", chdir: "path/to/repo")` This allows you to perform advanced operations where you might need to supply environment variables or options like changing directory (as shown in the example). Check the method signatures to learn more.
76
80
 
77
81
  === Commands
78
82
 
@@ -165,6 +169,12 @@ stdout, stderr, status = tag.call
165
169
  # Creates a new tag.
166
170
  tag.create "0.0.0", "Version 0.0.0"
167
171
 
172
+ # Deletes local tag.
173
+ tag.delete_local "0.0.0"
174
+
175
+ # Deletes remote tag.
176
+ tag.delete_remote "0.0.0"
177
+
168
178
  # Answers true or false base on whether local and remote tag exist.
169
179
  tag.exist? "0.1.0"
170
180
 
@@ -331,6 +341,19 @@ describe Demo do
331
341
  end
332
342
  ----
333
343
 
344
+ ==== Git Tag
345
+
346
+ Provides a default `git_tag` record of `Gitt::Models::Tag` with minimal information for testing purposes and can be used as follows:
347
+
348
+ [source,ruby]
349
+ ----
350
+ require "gitt/rspec/shared_contexts/git_tag"
351
+
352
+ describe Demo do
353
+ include_context "with Git tag"
354
+ end
355
+ ----
356
+
334
357
  ==== Git Repository
335
358
 
336
359
  Provides a simple Git repository with a single commit for testing purposes. This repository is set up and torn down _around_ each spec. The repository is built within your project's `tmp` directory and provides a `git_repo_dir` pathname you can interact with. Here's how to use it:
data/gitt.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "gitt"
5
- spec.version = "4.0.0"
5
+ spec.version = "4.1.0"
6
6
  spec.authors = ["Brooke Kuhlmann"]
7
7
  spec.email = ["brooke@alchemists.io"]
8
8
  spec.homepage = "https://alchemists.io/projects/gitt"
@@ -12,16 +12,16 @@ module Gitt
12
12
  @shell = shell
13
13
  end
14
14
 
15
- def default fallback = "main"
16
- shell.call("config", "init.defaultBranch")
15
+ def default(fallback = "main", *, **)
16
+ shell.call("config", "init.defaultBranch", *, **)
17
17
  .fmap(&:chomp)
18
18
  .fmap { |name| name.empty? ? fallback : name }
19
19
  .or(Success(fallback))
20
20
  end
21
21
 
22
- def call(*) = shell.call("branch", *)
22
+ def call(*, **) = shell.call("branch", *, **)
23
23
 
24
- def name = shell.call("rev-parse", "--abbrev-ref", "HEAD").fmap(&:chomp)
24
+ def name(*, **) = shell.call("rev-parse", "--abbrev-ref", "HEAD", *, **).fmap(&:chomp)
25
25
 
26
26
  private
27
27
 
@@ -13,16 +13,17 @@ module Gitt
13
13
  @shell = shell
14
14
  end
15
15
 
16
- def call(*) = shell.call("config", *)
16
+ def call(*, **) = shell.call("config", *, **)
17
17
 
18
- def get(key, fallback = Core::EMPTY_STRING, *)
19
- call(*, "--get", key).fmap(&:chomp)
20
- .or { |error| block_given? ? yield(error) : Success(fallback) }
18
+ def get(key, fallback = Core::EMPTY_STRING, *, **)
19
+ shell.call("config", "--get", key, *, **)
20
+ .fmap(&:chomp)
21
+ .or { |error| block_given? ? yield(error) : Success(fallback) }
21
22
  end
22
23
 
23
24
  def origin? = !get("remote.origin.url").value_or(Core::EMPTY_STRING).empty?
24
25
 
25
- def set(key, value, *) = call(*, "--add", key, value).fmap { value }
26
+ def set(key, value, *, **) = shell.call("config", "--add", key, value, *, **).fmap { value }
26
27
 
27
28
  private
28
29
 
@@ -35,11 +35,11 @@ module Gitt
35
35
  @parser = parser
36
36
  end
37
37
 
38
- def call(*) = shell.call("log", *)
38
+ def call(*, **) = shell.call("log", *, **)
39
39
 
40
- def index *arguments
40
+ def index(*arguments, **)
41
41
  arguments.prepend("--shortstat", pretty_format)
42
- .then { |pretty_format| call(*pretty_format) }
42
+ .then { |pretty_format| call(*pretty_format, **) }
43
43
  .fmap { |content| String(content).scrub("?") }
44
44
  .fmap { |entries| build_records entries }
45
45
  end
@@ -33,7 +33,7 @@ module Gitt
33
33
  @parser = parser
34
34
  end
35
35
 
36
- def call(*) = shell.call("tag", *)
36
+ def call(*, **) = shell.call("tag", *, **)
37
37
 
38
38
  def create version, body = Core::EMPTY_STRING, *flags
39
39
  return Failure "Unable to create Git tag without version." unless version
@@ -45,17 +45,30 @@ module Gitt
45
45
  end
46
46
  end
47
47
 
48
+ def delete_local(version, *, **)
49
+ call("--delete", version, *, **).fmap { |text| text[/\d+\.\d+\.\d+/] }
50
+ .alt_map do |error|
51
+ error.delete_prefix("error: tag ").chomp
52
+ end
53
+ end
54
+
55
+ def delete_remote(version, *, **)
56
+ shell.call("push", "--delete", "origin", version, *, **)
57
+ .fmap { version }
58
+ .alt_map { |error| error.gsub("error: ", "").chomp }
59
+ end
60
+
48
61
  def exist?(version) = local?(version) || remote?(version)
49
62
 
50
- def index *arguments
63
+ def index(*arguments, **)
51
64
  arguments.prepend(pretty_format, "--list")
52
- .then { |flags| call(*flags) }
65
+ .then { |flags| call(*flags, **) }
53
66
  .fmap { |content| String(content).scrub("?").split %("\n") }
54
67
  .fmap { |entries| build_records entries }
55
68
  end
56
69
 
57
- def last
58
- shell.call("describe", "--abbrev=0", "--tags")
70
+ def last(*, **)
71
+ shell.call("describe", "--abbrev=0", "--tags", *, **)
59
72
  .fmap(&:strip)
60
73
  .or do |error|
61
74
  if error.match?(/no names found/i)
@@ -70,7 +83,7 @@ module Gitt
70
83
  call("--list", version).value_or(Core::EMPTY_STRING).match?(/\A#{version}\Z/)
71
84
  end
72
85
 
73
- def push = shell.call "push", "--tags"
86
+ def push(*, **) = shell.call("push", "--tags", *, **)
74
87
 
75
88
  def remote? version
76
89
  shell.call("ls-remote", "--tags", "origin", version)
@@ -78,8 +91,8 @@ module Gitt
78
91
  .match?(%r(.+tags/#{version}\Z))
79
92
  end
80
93
 
81
- def show version
82
- call(pretty_format, "--list", version).fmap { |content| parser.call content }
94
+ def show(version, *, **)
95
+ call(pretty_format, "--list", version, *, **).fmap { |content| parser.call content }
83
96
  end
84
97
 
85
98
  def tagged? = !call.value_or(Core::EMPTY_STRING).empty?
@@ -21,7 +21,7 @@ module Gitt
21
21
 
22
22
  def branch_default(...) = commands.fetch(:branch).default(...)
23
23
 
24
- def branch_name = commands.fetch(:branch).name
24
+ def branch_name(...) = commands.fetch(:branch).name(...)
25
25
 
26
26
  def call(...) = shell.call(...)
27
27
 
@@ -52,7 +52,11 @@ module Gitt
52
52
 
53
53
  def tag_create(...) = commands.fetch(:tag).create(...)
54
54
 
55
- def tag_last = commands.fetch(:tag).last
55
+ def tag_delete_local(...) = commands.fetch(:tag).delete_local(...)
56
+
57
+ def tag_delete_remote(...) = commands.fetch(:tag).delete_remote(...)
58
+
59
+ def tag_last(...) = commands.fetch(:tag).last(...)
56
60
 
57
61
  def tag_local?(...) = commands.fetch(:tag).local?(...)
58
62
 
@@ -62,7 +66,7 @@ module Gitt
62
66
 
63
67
  def tagged? = commands.fetch(:tag).tagged?
64
68
 
65
- def tags_push = commands.fetch(:tag).push
69
+ def tags_push(...) = commands.fetch(:tag).push(...)
66
70
 
67
71
  def uncommitted(...) = commands.fetch(:log).uncommitted(...)
68
72
 
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.shared_context "with Git tag" do
4
+ let :git_tag do
5
+ Gitt::Models::Tag[
6
+ author_email: "test@example.com",
7
+ author_name: "Test User",
8
+ authored_at: 1735714800,
9
+ authored_relative_at: "1 day ago",
10
+ body: "Generated by Milestoner.",
11
+ committed_at: 1735718461,
12
+ committed_relative_at: "1 hour ago",
13
+ committer_email: "test@example.com",
14
+ committer_name: "Test User",
15
+ sha: "180dec7d8ae8cbe3565a727c63c2111e49e0b737",
16
+ signature: "",
17
+ subject: "Version 0.0.0",
18
+ trailers: [],
19
+ version: "0.0.0"
20
+ ]
21
+ end
22
+ end
data/lib/gitt/shell.rb CHANGED
@@ -12,8 +12,10 @@ module Gitt
12
12
  @client = client
13
13
  end
14
14
 
15
- def call(*, **)
16
- client.capture3("git", *, **).then do |stdout, stderr, status|
15
+ def call(*all, **)
16
+ environment, arguments = all.partition { it.is_a? Hash }
17
+
18
+ client.capture3(*environment, "git", *arguments, **).then do |stdout, stderr, status|
17
19
  status.success? ? Success(stdout) : Failure(stderr)
18
20
  end
19
21
  end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitt
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0
4
+ version: 4.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brooke Kuhlmann
@@ -34,7 +34,7 @@ cert_chain:
34
34
  3n5C8/6Zh9DYTkpcwPSuIfAga6wf4nXc9m6JAw8AuMLaiWN/r/2s4zJsUHYERJEu
35
35
  gZGm4JqtuSg8pYjPeIJxS960owq+SfuC+jxqmRA54BisFCv/0VOJi7tiJVY=
36
36
  -----END CERTIFICATE-----
37
- date: 2024-12-27 00:00:00.000000000 Z
37
+ date: 2025-01-12 00:00:00.000000000 Z
38
38
  dependencies:
39
39
  - !ruby/object:Gem::Dependency
40
40
  name: core
@@ -121,6 +121,7 @@ files:
121
121
  - lib/gitt/repository.rb
122
122
  - lib/gitt/rspec/shared_contexts/git_commit.rb
123
123
  - lib/gitt/rspec/shared_contexts/git_repo.rb
124
+ - lib/gitt/rspec/shared_contexts/git_tag.rb
124
125
  - lib/gitt/rspec/shared_contexts/temp_dir.rb
125
126
  - lib/gitt/sanitizers/container.rb
126
127
  - lib/gitt/sanitizers/date.rb
metadata.gz.sig CHANGED
Binary file