gitflash 0.4.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 +14 -2
- data/README.md +53 -5
- data/command_descriptions.yml +36 -21
- data/lib/gitflash/branch.rb +44 -0
- data/lib/gitflash/cli.rb +46 -104
- 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/confirmation_required.rb +19 -0
- data/lib/gitflash/error.rb +23 -0
- data/lib/gitflash/git/bash_command.rb +8 -6
- data/lib/gitflash/git/command_error.rb +5 -1
- 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 +15 -2
- data/lib/gitflash/git/wrapper.rb +0 -86
data/lib/gitflash/git/wrapper.rb
DELETED
|
@@ -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
|