gitflash 0.4.0 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/schema/v1.json ADDED
@@ -0,0 +1,172 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://github.com/Kleanthismits/git_flash/blob/main/schema/v1.json",
4
+ "title": "gitflash --json output, schema version 1",
5
+ "description": "Every gitflash command run with --json prints exactly one object in this envelope. `ok` is true for the statuses done, planned, noop and cancelled. Fields may be added in later releases of version 1; existing fields keep their meaning.",
6
+ "type": "object",
7
+ "required": ["schema", "command", "ok", "status", "dry_run"],
8
+ "properties": {
9
+ "schema": { "const": 1 },
10
+ "command": { "enum": ["branches", "checkout", "delete", "reset"] },
11
+ "ok": { "type": "boolean" },
12
+ "status": {
13
+ "description": "done: the change was made. planned: --dry-run, nothing changed. noop: nothing to do. cancelled: the user declined. failed: git refused part of the change. confirmation_required: re-run with --yes after reviewing `plan`. error: invalid input or environment.",
14
+ "enum": ["done", "planned", "noop", "cancelled", "failed", "confirmation_required", "error"]
15
+ },
16
+ "dry_run": { "type": "boolean" },
17
+ "plan": { "type": "object", "description": "The change that will be, would be or was made." },
18
+ "result": { "type": "object", "description": "What happened, including what is needed to revert it." },
19
+ "error": { "$ref": "#/$defs/error" }
20
+ },
21
+ "allOf": [
22
+ {
23
+ "if": { "properties": { "status": { "enum": ["done", "planned", "noop", "cancelled"] } } },
24
+ "then": { "properties": { "ok": { "const": true } }, "not": { "required": ["error"] } },
25
+ "else": { "properties": { "ok": { "const": false } }, "required": ["error"] }
26
+ },
27
+ {
28
+ "if": { "properties": { "status": { "const": "confirmation_required" } } },
29
+ "then": { "required": ["plan"] }
30
+ },
31
+ {
32
+ "if": { "properties": { "command": { "const": "branches" } } },
33
+ "then": { "properties": { "result": { "$ref": "#/$defs/branches_result" } } }
34
+ },
35
+ {
36
+ "if": { "properties": { "command": { "const": "checkout" } } },
37
+ "then": {
38
+ "properties": {
39
+ "plan": { "$ref": "#/$defs/checkout_plan" },
40
+ "result": { "$ref": "#/$defs/checkout_result" }
41
+ }
42
+ }
43
+ },
44
+ {
45
+ "if": { "properties": { "command": { "const": "delete" } } },
46
+ "then": {
47
+ "properties": {
48
+ "plan": { "$ref": "#/$defs/delete_plan" },
49
+ "result": { "$ref": "#/$defs/delete_result" }
50
+ }
51
+ }
52
+ },
53
+ {
54
+ "if": { "properties": { "command": { "const": "reset" } } },
55
+ "then": {
56
+ "properties": {
57
+ "plan": { "$ref": "#/$defs/reset_plan" },
58
+ "result": { "$ref": "#/$defs/reset_result" }
59
+ }
60
+ }
61
+ }
62
+ ],
63
+ "$defs": {
64
+ "sha": { "type": "string", "pattern": "^[0-9a-f]{4,64}$" },
65
+ "error": {
66
+ "type": "object",
67
+ "required": ["code", "message", "exit_code"],
68
+ "properties": {
69
+ "code": {
70
+ "description": "Stable identifier to branch on; the message is for humans.",
71
+ "enum": [
72
+ "not_a_repository", "input_required", "invalid_usage", "invalid_options",
73
+ "unknown_branch", "unknown_commit", "protected_branch",
74
+ "confirmation_required", "git_failed", "failed"
75
+ ]
76
+ },
77
+ "message": { "type": "string" },
78
+ "exit_code": { "enum": [1, 2] }
79
+ }
80
+ },
81
+ "branch": {
82
+ "type": "object",
83
+ "required": [
84
+ "name", "sha", "current", "default", "upstream", "upstream_gone", "ahead", "behind",
85
+ "merged", "last_commit_at", "last_commit_author", "last_commit_subject"
86
+ ],
87
+ "properties": {
88
+ "name": { "type": "string" },
89
+ "sha": { "$ref": "#/$defs/sha" },
90
+ "current": { "type": "boolean" },
91
+ "default": { "type": "boolean", "description": "The branch origin/HEAD points to, else main or master." },
92
+ "upstream": { "type": ["string", "null"] },
93
+ "upstream_gone": { "type": "boolean", "description": "The upstream branch was deleted on the remote." },
94
+ "ahead": { "type": "integer", "minimum": 0 },
95
+ "behind": { "type": "integer", "minimum": 0 },
96
+ "merged": { "type": ["boolean", "null"], "description": "Merged into the default branch; null when there is no default branch." },
97
+ "last_commit_at": { "type": "string", "format": "date-time" },
98
+ "last_commit_author": { "type": "string" },
99
+ "last_commit_subject": { "type": "string" }
100
+ }
101
+ },
102
+ "branches_result": {
103
+ "type": "object",
104
+ "required": ["default_branch", "branches"],
105
+ "properties": {
106
+ "default_branch": { "type": ["string", "null"] },
107
+ "branches": { "type": "array", "items": { "$ref": "#/$defs/branch" } }
108
+ }
109
+ },
110
+ "checkout_plan": {
111
+ "type": "object",
112
+ "required": ["branch"],
113
+ "properties": { "branch": { "type": "string" } }
114
+ },
115
+ "checkout_result": {
116
+ "type": "object",
117
+ "required": ["branch", "previous_branch"],
118
+ "properties": {
119
+ "branch": { "type": ["string", "null"] },
120
+ "previous_branch": { "type": ["string", "null"], "description": "Check this out to go back; null on a detached HEAD." }
121
+ }
122
+ },
123
+ "delete_plan": {
124
+ "type": "object",
125
+ "required": ["branches", "force"],
126
+ "properties": {
127
+ "branches": { "type": "array", "items": { "type": "string" } },
128
+ "force": { "type": "boolean" }
129
+ }
130
+ },
131
+ "delete_result": {
132
+ "type": "object",
133
+ "required": ["deleted", "failed"],
134
+ "properties": {
135
+ "deleted": {
136
+ "type": "array",
137
+ "description": "Recreate a branch with: git branch NAME SHA",
138
+ "items": {
139
+ "type": "object",
140
+ "required": ["branch", "sha"],
141
+ "properties": { "branch": { "type": "string" }, "sha": { "$ref": "#/$defs/sha" } }
142
+ }
143
+ },
144
+ "failed": {
145
+ "type": "array",
146
+ "items": {
147
+ "type": "object",
148
+ "required": ["branch", "error"],
149
+ "properties": { "branch": { "type": "string" }, "error": { "type": "string" } }
150
+ }
151
+ }
152
+ }
153
+ },
154
+ "reset_plan": {
155
+ "type": "object",
156
+ "required": ["commit", "mode"],
157
+ "properties": {
158
+ "commit": { "$ref": "#/$defs/sha" },
159
+ "mode": { "enum": ["soft", "mixed", "hard"] }
160
+ }
161
+ },
162
+ "reset_result": {
163
+ "type": "object",
164
+ "required": ["commit", "mode", "previous_commit"],
165
+ "properties": {
166
+ "commit": { "$ref": "#/$defs/sha" },
167
+ "mode": { "enum": ["soft", "mixed", "hard"] },
168
+ "previous_commit": { "$ref": "#/$defs/sha", "description": "Reset to this commit to go back. Uncommitted changes lost by a hard reset cannot be restored this way." }
169
+ }
170
+ }
171
+ }
172
+ }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitflash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kleanthis Mitsioulis
@@ -73,13 +73,27 @@ files:
73
73
  - bin/gitflash
74
74
  - command_descriptions.yml
75
75
  - lib/gitflash.rb
76
+ - lib/gitflash/branch.rb
76
77
  - lib/gitflash/cli.rb
78
+ - lib/gitflash/commands/base.rb
79
+ - lib/gitflash/commands/branches.rb
80
+ - lib/gitflash/commands/checkout.rb
81
+ - lib/gitflash/commands/delete.rb
82
+ - lib/gitflash/commands/reset.rb
83
+ - lib/gitflash/commit.rb
77
84
  - lib/gitflash/configuration.rb
85
+ - lib/gitflash/confirmation_required.rb
86
+ - lib/gitflash/error.rb
78
87
  - lib/gitflash/git/bash_command.rb
79
88
  - lib/gitflash/git/command_error.rb
80
- - lib/gitflash/git/wrapper.rb
81
89
  - lib/gitflash/prompt.rb
90
+ - lib/gitflash/repo.rb
91
+ - lib/gitflash/result.rb
92
+ - lib/gitflash/terminal_text.rb
93
+ - lib/gitflash/ui.rb
94
+ - lib/gitflash/usage_error.rb
82
95
  - lib/gitflash/version.rb
96
+ - schema/v1.json
83
97
  homepage: https://github.com/Kleanthismits/git_flash
84
98
  licenses:
85
99
  - MIT
@@ -101,7 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
101
115
  - !ruby/object:Gem::Version
102
116
  version: '0'
103
117
  requirements: []
104
- rubygems_version: 3.7.2
118
+ rubygems_version: 4.0.22
105
119
  specification_version: 4
106
120
  summary: Simplified usage of some git cli commands
107
121
  test_files: []
@@ -1,86 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Gitflash
4
- module Git
5
- class Wrapper
6
- COMMITS_LIMIT = 100
7
-
8
- class << self
9
- def local_branches(current: true, master: true)
10
- formatted_branches - hidden_branches(current, master)
11
- end
12
-
13
- def all_local_branches
14
- formatted_branches
15
- end
16
-
17
- # Raises CommandError when the working directory is not inside a git repository
18
- def inside_work_tree!
19
- output = bash.exec('git', 'rev-parse', '--is-inside-work-tree').strip
20
- raise CommandError, 'Not inside a git work tree' unless output == 'true'
21
- end
22
-
23
- def current_branch
24
- bash.exec('git', 'branch', '--show-current').strip
25
- end
26
-
27
- def checkout(branch)
28
- bash.system_exec('git', 'checkout', branch, '--')
29
- end
30
-
31
- def delete(branch)
32
- bash.system_exec('git', 'branch', '-D', *branch)
33
- end
34
-
35
- def reset(commit_hash:, hard:)
36
- params = [].tap do |ar|
37
- ar << '--hard' if hard
38
- end
39
-
40
- bash.system_exec('git', 'reset', *params, commit_hash, '--')
41
- end
42
-
43
- def branch_commits
44
- commits_string = bash.exec(
45
- 'git', 'log', "--max-count=#{COMMITS_LIMIT}", '--format=%h%x09%s'
46
- )
47
- parse_commits(commits_string)
48
- rescue CommandError
49
- # `git log` fails on a branch without commits
50
- {}
51
- end
52
-
53
- private
54
-
55
- def parse_commits(commits_string)
56
- {}.tap do |hsh|
57
- commits_string.each_line do |line|
58
- commit_code, commit_name = line.chomp.split("\t", 2)
59
- next if commit_code.nil? || commit_code.empty?
60
-
61
- hsh["#{commit_code} - #{commit_name}"] = commit_code
62
- end
63
- end
64
- end
65
-
66
- def hidden_branches(current, master)
67
- [].tap { |hb|
68
- hb.push('master', 'main') unless master
69
- hb.push(current_branch) unless current
70
- }.reject(&:empty?)
71
- end
72
-
73
- def formatted_branches
74
- bash.exec('git', 'for-each-ref', '--format=%(refname:short)', 'refs/heads/')
75
- .split("\n")
76
- .map(&:strip)
77
- .reject(&:empty?)
78
- end
79
-
80
- def bash
81
- BashCommand
82
- end
83
- end
84
- end
85
- end
86
- end