git_undo 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/gitundo +9 -0
- data/config/environment.rb +1 -0
- data/lib/git_undo/git_manager.rb +72 -0
- metadata +91 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1853641d4fa2c27843cd182b10778d67b8858275
|
4
|
+
data.tar.gz: d653f3b5f5e7be2bc42cad3f8aa4d44772202163
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 66aca25a347e2c1e0fbc5d3a2fc16af236679780c3dab97dfeb29ee8637ad0d6f52c5a1cce5d1b4fbc9369bd73cd2ea340dde8e9c03abbb15c0bf08c3feffbcf
|
7
|
+
data.tar.gz: 309266bd6ddc9b052b5dd4bd0d51b7e8debc3f14a9fbb04661d3c2b0abfbf0d2c41137a857f5a395153d572ba7ef480e5451d1e80c302daa87956de624871dbd
|
data/bin/gitundo
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require_relative '../lib/git_undo/git_manager.rb'
|
@@ -0,0 +1,72 @@
|
|
1
|
+
class GitManager
|
2
|
+
def initialize(history_file)
|
3
|
+
@history_file = history_file
|
4
|
+
@command_list = []
|
5
|
+
end
|
6
|
+
|
7
|
+
def get_commands
|
8
|
+
File.open(@history_file) do |file|
|
9
|
+
file.each do |line|
|
10
|
+
# find last git command
|
11
|
+
if /\Agit / =~ line
|
12
|
+
@command_list << line.chomp
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def last_command
|
19
|
+
@command_list.last
|
20
|
+
end
|
21
|
+
|
22
|
+
def run
|
23
|
+
get_commands
|
24
|
+
puts "Last git command was: `#{last_command}`"
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.setup
|
28
|
+
puts "It looks like you haven't run the initial setup. Would you like to do so now (y/n)?"
|
29
|
+
if gets.chomp.downcase == 'y'
|
30
|
+
puts "This will involve appending an alias to your .bash_profile. Okay to proceed?"
|
31
|
+
if gets.chomp.downcase == 'y'
|
32
|
+
puts "Thanks!"
|
33
|
+
update_bash_profile
|
34
|
+
else
|
35
|
+
puts "Goodbye!"
|
36
|
+
end
|
37
|
+
else
|
38
|
+
puts "Goodbye!"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.update_bash_profile
|
43
|
+
alias_exists = false
|
44
|
+
# last_line_alias = false
|
45
|
+
# position = 0
|
46
|
+
# line_count = 0
|
47
|
+
# index = 0
|
48
|
+
# max_line_count = 0
|
49
|
+
file = File.open(File.expand_path('~' + '/.bash_profile'),'r+')
|
50
|
+
|
51
|
+
file.readlines.each do |line|
|
52
|
+
# line_count += 1
|
53
|
+
if /\A[\s]*alias/.match line
|
54
|
+
if /\A[\s]*alias gitundo="HISTFILE=\$HISTFILE gitundo"\n\z/.match line
|
55
|
+
alias_exists = true
|
56
|
+
end
|
57
|
+
# max_line_count = line_count
|
58
|
+
# elsif last_line_alias
|
59
|
+
# position = file.pos
|
60
|
+
# last_line_alias = false
|
61
|
+
end
|
62
|
+
end
|
63
|
+
unless alias_exists
|
64
|
+
file.write("# Git Undo\n")
|
65
|
+
file.write("alias gitundo=\"HISTFILE=$HISTFILE gitundo\"\n")
|
66
|
+
puts "Please run `source ~/.bash_profile && cd .` to reload configuration"
|
67
|
+
end
|
68
|
+
file.close
|
69
|
+
# puts max_line_count + 1
|
70
|
+
# puts position
|
71
|
+
end
|
72
|
+
end
|
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: git_undo
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Randall Reed, Jr.
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-05-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.11'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.11'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
description: Command line utility to read from bash history, find last git command,
|
56
|
+
and output command to undo that operation.
|
57
|
+
email:
|
58
|
+
- randallreedjr@gmail.com
|
59
|
+
executables:
|
60
|
+
- gitundo
|
61
|
+
extensions: []
|
62
|
+
extra_rdoc_files: []
|
63
|
+
files:
|
64
|
+
- bin/gitundo
|
65
|
+
- config/environment.rb
|
66
|
+
- lib/git_undo/git_manager.rb
|
67
|
+
homepage: https://github.com/randallreedjr/git_undo
|
68
|
+
licenses:
|
69
|
+
- MIT
|
70
|
+
metadata: {}
|
71
|
+
post_install_message:
|
72
|
+
rdoc_options: []
|
73
|
+
require_paths:
|
74
|
+
- lib
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
requirements: []
|
86
|
+
rubyforge_project:
|
87
|
+
rubygems_version: 2.5.1
|
88
|
+
signing_key:
|
89
|
+
specification_version: 4
|
90
|
+
summary: Undo last git command
|
91
|
+
test_files: []
|