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.
@@ -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