git_undo 1.0.0 → 1.0.8
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/config/environment.rb +1 -1
- data/lib/git_undo.rb +3 -0
- data/lib/git_undo/git_manager.rb +12 -25
- data/lib/git_undo/git_reverser.rb +44 -0
- data/lib/git_undo/git_setup.rb +54 -0
- metadata +18 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 80b844dbe921e309545c109907cdbf20d345ed89
|
4
|
+
data.tar.gz: 85cc2756f7c94e49f9de5d03021daf58df24a24e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d91b8218bfcab8c35a16ff07c1f2683a82d5c2f8e9d041b2f82a99fbd31c6da97bbf2e7aad9c5f76c9cfafd5a1b1576ef2cd6b43c60e845dc0af14dbba54b560
|
7
|
+
data.tar.gz: 952b107a5d9e28207d441dd9b7d7e0d563e769640497f9ae18a748710e21f9bad752066408caf7a75093e528aebb4384e3d86497289e454a1fab4d723168cfe5
|
data/config/environment.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
require_relative '../lib/git_undo
|
1
|
+
require_relative '../lib/git_undo.rb'
|
data/lib/git_undo.rb
ADDED
data/lib/git_undo/git_manager.rb
CHANGED
@@ -1,8 +1,4 @@
|
|
1
|
-
require 'pry'
|
2
|
-
|
3
1
|
class GitManager
|
4
|
-
VALID_COMMANDS = ['add','commit','merge','checkout','co']
|
5
|
-
|
6
2
|
def initialize(history_file)
|
7
3
|
@history_file = history_file
|
8
4
|
@command_list = []
|
@@ -21,7 +17,7 @@ class GitManager
|
|
21
17
|
def get_commands
|
22
18
|
File.open(@history_file) do |file|
|
23
19
|
file.each do |line|
|
24
|
-
# find
|
20
|
+
# find all git commands
|
25
21
|
if /\Agit / =~ line
|
26
22
|
@command_list << line.chomp
|
27
23
|
end
|
@@ -30,16 +26,10 @@ class GitManager
|
|
30
26
|
end
|
31
27
|
|
32
28
|
def last_command
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
command = parse_command(@command_list[index])[:action]
|
37
|
-
if VALID_COMMANDS.include?(command)
|
38
|
-
last = @command_list[index]
|
39
|
-
end
|
40
|
-
index -= 1
|
29
|
+
@command_list.reverse.detect do |raw_command|
|
30
|
+
command = parse_command(raw_command)[:action]
|
31
|
+
GitReverser::VALID_COMMANDS.include?(command)
|
41
32
|
end
|
42
|
-
return last
|
43
33
|
end
|
44
34
|
|
45
35
|
def parse_command(command)
|
@@ -50,21 +40,19 @@ class GitManager
|
|
50
40
|
end
|
51
41
|
|
52
42
|
def undo_command(action, arguments)
|
43
|
+
reverser = GitReverser.new(arguments)
|
44
|
+
|
53
45
|
case action
|
54
46
|
when 'add'
|
55
|
-
|
47
|
+
reverser.reverse_add
|
56
48
|
when 'commit'
|
57
|
-
|
49
|
+
reverser.reverse_commit
|
58
50
|
when 'merge'
|
59
|
-
|
51
|
+
reverser.reverse_merge
|
60
52
|
when 'checkout','co'
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
branch_name = arguments.split.last
|
65
|
-
undo_command += " && git branch -D #{branch_name}"
|
66
|
-
end
|
67
|
-
undo_command
|
53
|
+
reverser.reverse_checkout
|
54
|
+
when 'rebase'
|
55
|
+
reverser.reverse_rebase
|
68
56
|
end
|
69
57
|
end
|
70
58
|
|
@@ -82,5 +70,4 @@ class GitManager
|
|
82
70
|
end
|
83
71
|
end
|
84
72
|
end
|
85
|
-
|
86
73
|
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
class GitReverser
|
2
|
+
attr_reader :arguments
|
3
|
+
|
4
|
+
VALID_COMMANDS = ['add','commit','merge','checkout','co', 'rebase']
|
5
|
+
|
6
|
+
def initialize(arguments)
|
7
|
+
@arguments = arguments
|
8
|
+
end
|
9
|
+
|
10
|
+
def reverse_add
|
11
|
+
"git reset #{arguments}"
|
12
|
+
end
|
13
|
+
|
14
|
+
def reverse_commit
|
15
|
+
'git reset --soft HEAD~'
|
16
|
+
end
|
17
|
+
|
18
|
+
def reverse_merge
|
19
|
+
'git reset --merge ORIG_HEAD'
|
20
|
+
end
|
21
|
+
|
22
|
+
def reverse_checkout
|
23
|
+
undo_command = "git checkout -"
|
24
|
+
if arguments.start_with?('-b')
|
25
|
+
#also delete branch
|
26
|
+
branch_name = arguments.split.last
|
27
|
+
undo_command += " && git branch -D #{branch_name}"
|
28
|
+
end
|
29
|
+
undo_command
|
30
|
+
end
|
31
|
+
|
32
|
+
def reverse_rebase
|
33
|
+
if !arguments.include?('-i')
|
34
|
+
current_branch_command = 'git rev-parse --abbrev-ref HEAD'
|
35
|
+
branch_name = %x[ #{current_branch_command} ].chomp
|
36
|
+
|
37
|
+
fetch_old_state = "git checkout #{branch_name}@{1}"
|
38
|
+
delete_branch = "git branch -D #{branch_name}"
|
39
|
+
recreate_branch = "git checkout -b #{branch_name}"
|
40
|
+
|
41
|
+
"#{fetch_old_state} && #{delete_branch} && #{recreate_branch}"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
class GitSetup
|
2
|
+
|
3
|
+
attr_reader :file
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@file = nil
|
7
|
+
end
|
8
|
+
|
9
|
+
def run
|
10
|
+
puts "It looks like you haven't run the initial setup. Would you like to do so now? (y/N)"
|
11
|
+
if gets.chomp.downcase == 'y'
|
12
|
+
puts "This will involve appending an alias to your .bash_profile. Okay to proceed? (y/N)"
|
13
|
+
if gets.chomp.downcase == 'y'
|
14
|
+
puts "Thanks!"
|
15
|
+
update_bash_profile
|
16
|
+
else
|
17
|
+
puts "Goodbye!"
|
18
|
+
end
|
19
|
+
else
|
20
|
+
puts "Goodbye!"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def update_bash_profile
|
25
|
+
@file = File.open(File.expand_path('~' + '/.bash_profile'),'r+')
|
26
|
+
|
27
|
+
unless alias_exists?
|
28
|
+
write_to_bash_profile
|
29
|
+
puts "Please run `source ~/.bash_profile && cd .` to reload configuration"
|
30
|
+
end
|
31
|
+
file.close
|
32
|
+
end
|
33
|
+
|
34
|
+
def alias_exists?
|
35
|
+
alias_exists = false
|
36
|
+
|
37
|
+
file.readlines.each do |line|
|
38
|
+
if /\A[\s]*alias/.match line
|
39
|
+
if /\A[\s]*alias git-undo="HISTFILE=\$HISTFILE git-undo"\n\z/.match line
|
40
|
+
alias_exists = true
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
return alias_exists
|
46
|
+
end
|
47
|
+
|
48
|
+
def write_to_bash_profile
|
49
|
+
file.write("# Git Undo\n")
|
50
|
+
file.write("alias git-undo=\"HISTFILE=$HISTFILE git-undo\"\n")
|
51
|
+
file.write("# Flush history immediately")
|
52
|
+
file.write("export PROMPT_COMMAND='history -a")
|
53
|
+
end
|
54
|
+
end
|
metadata
CHANGED
@@ -1,69 +1,69 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: git_undo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Randall Reed, Jr.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-06-
|
11
|
+
date: 2016-06-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.11'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.11'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - ~>
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '10.0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - ~>
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - ~>
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '3.0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - ~>
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: pry
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
description: Command line utility to read from bash history, find last git command,
|
@@ -75,9 +75,12 @@ executables:
|
|
75
75
|
extensions: []
|
76
76
|
extra_rdoc_files: []
|
77
77
|
files:
|
78
|
-
- lib/git_undo/git_manager.rb
|
79
|
-
- config/environment.rb
|
80
78
|
- bin/git-undo
|
79
|
+
- config/environment.rb
|
80
|
+
- lib/git_undo.rb
|
81
|
+
- lib/git_undo/git_manager.rb
|
82
|
+
- lib/git_undo/git_reverser.rb
|
83
|
+
- lib/git_undo/git_setup.rb
|
81
84
|
homepage: https://github.com/randallreedjr/git_undo
|
82
85
|
licenses:
|
83
86
|
- MIT
|
@@ -88,17 +91,17 @@ require_paths:
|
|
88
91
|
- lib
|
89
92
|
required_ruby_version: !ruby/object:Gem::Requirement
|
90
93
|
requirements:
|
91
|
-
- -
|
94
|
+
- - ">="
|
92
95
|
- !ruby/object:Gem::Version
|
93
96
|
version: '0'
|
94
97
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
98
|
requirements:
|
96
|
-
- -
|
99
|
+
- - ">="
|
97
100
|
- !ruby/object:Gem::Version
|
98
101
|
version: '0'
|
99
102
|
requirements: []
|
100
103
|
rubyforge_project:
|
101
|
-
rubygems_version: 2.
|
104
|
+
rubygems_version: 2.4.8
|
102
105
|
signing_key:
|
103
106
|
specification_version: 4
|
104
107
|
summary: Undo last git command
|