gitflash 0.3.0 → 0.5.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +55 -0
- data/README.md +63 -4
- data/bin/gitflash +2 -1
- data/command_descriptions.yml +36 -21
- data/lib/gitflash/branch.rb +44 -0
- data/lib/gitflash/cli.rb +50 -86
- data/lib/gitflash/commands/base.rb +38 -0
- data/lib/gitflash/commands/branches.rb +68 -0
- data/lib/gitflash/commands/checkout.rb +47 -0
- data/lib/gitflash/commands/delete.rb +106 -0
- data/lib/gitflash/commands/reset.rb +67 -0
- data/lib/gitflash/commit.rb +22 -0
- data/lib/gitflash/configuration.rb +3 -1
- data/lib/gitflash/confirmation_required.rb +19 -0
- data/lib/gitflash/error.rb +23 -0
- data/lib/gitflash/git/bash_command.rb +15 -4
- data/lib/gitflash/git/command_error.rb +11 -0
- data/lib/gitflash/prompt.rb +2 -2
- data/lib/gitflash/repo.rb +116 -0
- data/lib/gitflash/result.rb +8 -0
- data/lib/gitflash/ui.rb +93 -0
- data/lib/gitflash/usage_error.rb +14 -0
- data/lib/gitflash/version.rb +1 -1
- data/schema/v1.json +172 -0
- metadata +30 -29
- data/bin/console +0 -15
- data/bin/setup +0 -8
- data/lib/gitflash/git/wrapper.rb +0 -80
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,29 +1,34 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: gitflash
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.5.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Kleanthis Mitsioulis
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: thor
|
|
15
14
|
requirement: !ruby/object:Gem::Requirement
|
|
16
15
|
requirements:
|
|
17
|
-
- - "
|
|
16
|
+
- - ">="
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '1.4'
|
|
19
|
+
- - "<"
|
|
18
20
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: '
|
|
21
|
+
version: '2'
|
|
20
22
|
type: :runtime
|
|
21
23
|
prerelease: false
|
|
22
24
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
25
|
requirements:
|
|
24
|
-
- - "
|
|
26
|
+
- - ">="
|
|
27
|
+
- !ruby/object:Gem::Version
|
|
28
|
+
version: '1.4'
|
|
29
|
+
- - "<"
|
|
25
30
|
- !ruby/object:Gem::Version
|
|
26
|
-
version: '
|
|
31
|
+
version: '2'
|
|
27
32
|
- !ruby/object:Gem::Dependency
|
|
28
33
|
name: tty-prompt
|
|
29
34
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -52,20 +57,6 @@ dependencies:
|
|
|
52
57
|
- - "~>"
|
|
53
58
|
- !ruby/object:Gem::Version
|
|
54
59
|
version: '2.6'
|
|
55
|
-
- !ruby/object:Gem::Dependency
|
|
56
|
-
name: rake
|
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
|
58
|
-
requirements:
|
|
59
|
-
- - "~>"
|
|
60
|
-
- !ruby/object:Gem::Version
|
|
61
|
-
version: '13.0'
|
|
62
|
-
type: :development
|
|
63
|
-
prerelease: false
|
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
-
requirements:
|
|
66
|
-
- - "~>"
|
|
67
|
-
- !ruby/object:Gem::Version
|
|
68
|
-
version: '13.0'
|
|
69
60
|
description: This gem allows you to perform a number of git commands using interactive
|
|
70
61
|
cli prompts
|
|
71
62
|
email:
|
|
@@ -76,28 +67,39 @@ extensions: []
|
|
|
76
67
|
extra_rdoc_files:
|
|
77
68
|
- README.md
|
|
78
69
|
files:
|
|
70
|
+
- CHANGELOG.md
|
|
79
71
|
- LICENSE
|
|
80
72
|
- README.md
|
|
81
|
-
- bin/console
|
|
82
73
|
- bin/gitflash
|
|
83
|
-
- bin/setup
|
|
84
74
|
- command_descriptions.yml
|
|
85
75
|
- lib/gitflash.rb
|
|
76
|
+
- lib/gitflash/branch.rb
|
|
86
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
|
|
87
84
|
- lib/gitflash/configuration.rb
|
|
85
|
+
- lib/gitflash/confirmation_required.rb
|
|
86
|
+
- lib/gitflash/error.rb
|
|
88
87
|
- lib/gitflash/git/bash_command.rb
|
|
89
|
-
- lib/gitflash/git/
|
|
88
|
+
- lib/gitflash/git/command_error.rb
|
|
90
89
|
- lib/gitflash/prompt.rb
|
|
90
|
+
- lib/gitflash/repo.rb
|
|
91
|
+
- lib/gitflash/result.rb
|
|
92
|
+
- lib/gitflash/ui.rb
|
|
93
|
+
- lib/gitflash/usage_error.rb
|
|
91
94
|
- lib/gitflash/version.rb
|
|
95
|
+
- schema/v1.json
|
|
92
96
|
homepage: https://github.com/Kleanthismits/git_flash
|
|
93
97
|
licenses:
|
|
94
98
|
- MIT
|
|
95
99
|
metadata:
|
|
96
|
-
homepage_uri: https://github.com/Kleanthismits/git_flash
|
|
97
100
|
source_code_uri: https://github.com/Kleanthismits/git_flash
|
|
98
101
|
changelog_uri: https://github.com/Kleanthismits/git_flash/blob/main/CHANGELOG.md
|
|
99
102
|
rubygems_mfa_required: 'true'
|
|
100
|
-
post_install_message:
|
|
101
103
|
rdoc_options: []
|
|
102
104
|
require_paths:
|
|
103
105
|
- lib
|
|
@@ -105,15 +107,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
105
107
|
requirements:
|
|
106
108
|
- - ">="
|
|
107
109
|
- !ruby/object:Gem::Version
|
|
108
|
-
version: '3.
|
|
110
|
+
version: '3.3'
|
|
109
111
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
110
112
|
requirements:
|
|
111
113
|
- - ">="
|
|
112
114
|
- !ruby/object:Gem::Version
|
|
113
115
|
version: '0'
|
|
114
116
|
requirements: []
|
|
115
|
-
rubygems_version: 3.
|
|
116
|
-
signing_key:
|
|
117
|
+
rubygems_version: 3.7.2
|
|
117
118
|
specification_version: 4
|
|
118
119
|
summary: Simplified usage of some git cli commands
|
|
119
120
|
test_files: []
|
data/bin/console
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env ruby
|
|
2
|
-
# frozen_string_literal: true
|
|
3
|
-
|
|
4
|
-
require 'bundler/setup'
|
|
5
|
-
require 'gitflash'
|
|
6
|
-
|
|
7
|
-
# You can add fixtures and/or initialization code here to make experimenting
|
|
8
|
-
# with your gem easier. You can also use a different console, if you like.
|
|
9
|
-
|
|
10
|
-
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
11
|
-
# require "pry"
|
|
12
|
-
# Pry.start
|
|
13
|
-
|
|
14
|
-
require 'irb'
|
|
15
|
-
IRB.start(__FILE__)
|
data/bin/setup
DELETED
data/lib/gitflash/git/wrapper.rb
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Gitflash
|
|
4
|
-
module Git
|
|
5
|
-
class Wrapper
|
|
6
|
-
HIDDEN_BRANCHES = %w[–show-current].freeze
|
|
7
|
-
|
|
8
|
-
class << self
|
|
9
|
-
def local_branches(current: true, master: true)
|
|
10
|
-
formatted_branches.tap do |branches|
|
|
11
|
-
hidden_branches(current, master).each { |br| branches.delete(br) }
|
|
12
|
-
end
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def all_local_branches
|
|
16
|
-
formatted_branches
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def current_branch
|
|
20
|
-
bash.exec('git branch --show-current').strip
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def checkout(branch)
|
|
24
|
-
bash.system_exec('git', 'checkout', branch)
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
def delete(branch)
|
|
28
|
-
bash.system_exec('git', 'branch', '-D', *branch)
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def reset(commit_hash:, hard:)
|
|
32
|
-
params = [].tap do |ar|
|
|
33
|
-
ar << '--hard' if hard
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
bash.system_exec('git', 'reset', *params, commit_hash)
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def branch_commits
|
|
40
|
-
commits_string = bash.exec('git log --oneline')
|
|
41
|
-
{}.tap do |hsh|
|
|
42
|
-
commits_string.each_line do |line|
|
|
43
|
-
parts = line.strip.split
|
|
44
|
-
commit_code = parts[0]
|
|
45
|
-
commit_name = parts[1..].join(' ')
|
|
46
|
-
label = "#{commit_code} - #{commit_name}"
|
|
47
|
-
hsh[label] = commit_code
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
private
|
|
53
|
-
|
|
54
|
-
def hidden_branches(current, master)
|
|
55
|
-
[].tap { |hb|
|
|
56
|
-
hb.push('master') unless master
|
|
57
|
-
hb.push('main') unless master
|
|
58
|
-
hb.push(current_branch) unless current
|
|
59
|
-
} + HIDDEN_BRANCHES
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
def formatted_branches
|
|
63
|
-
raw_branches.map do |str|
|
|
64
|
-
next str unless str.start_with?('* ')
|
|
65
|
-
|
|
66
|
-
str.gsub('* ', '')
|
|
67
|
-
end
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
def raw_branches
|
|
71
|
-
bash.exec('git branch').strip.split("\n").map(&:strip)
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
def bash
|
|
75
|
-
BashCommand
|
|
76
|
-
end
|
|
77
|
-
end
|
|
78
|
-
end
|
|
79
|
-
end
|
|
80
|
-
end
|