gitnext 0.1.1
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.
- data/bin/gitnext +8 -0
- data/gitnext.gemspec +21 -0
- data/lib/git_next.rb +89 -0
- data/spec/git_next_spec.rb +129 -0
- metadata +100 -0
data/bin/gitnext
ADDED
data/gitnext.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'gitnext'
|
3
|
+
s.version = '0.1.1'
|
4
|
+
s.summary = 'Simple method to move forward or backwards through a git repo'
|
5
|
+
s.platform = Gem::Platform::RUBY
|
6
|
+
s.authors = ["Nigel"]
|
7
|
+
s.email = ["nigelr@brisbanerails.com"]
|
8
|
+
s.homepage = "http://github.com/nigelr/gitnext"
|
9
|
+
s.has_rdoc = false
|
10
|
+
|
11
|
+
s.files = Dir.glob("{spec,lib}/**/*.rb") +
|
12
|
+
Dir.glob("bin/*") +
|
13
|
+
%w(gitnext.gemspec )
|
14
|
+
|
15
|
+
s.bindir = 'bin'
|
16
|
+
s.require_path = 'lib'
|
17
|
+
s.executables << %q{gitnext}
|
18
|
+
|
19
|
+
s.add_development_dependency 'rspec', '~> 2.1.0'
|
20
|
+
s.add_dependency 'git', '1.2.5'
|
21
|
+
end
|
data/lib/git_next.rb
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
require "git"
|
3
|
+
|
4
|
+
class GitNext
|
5
|
+
|
6
|
+
CONFIG_FILE = "/.git/gitnext.config"
|
7
|
+
|
8
|
+
def self.run current_path, args=""
|
9
|
+
usage_message = "Usage: gitnext [help, init, prev, top, bottom]"
|
10
|
+
@current_path = current_path
|
11
|
+
if File.exists? File.join @current_path, ".git"
|
12
|
+
@git = Git.open @current_path
|
13
|
+
|
14
|
+
if File.exist?(@current_path + CONFIG_FILE)
|
15
|
+
case args
|
16
|
+
when "top"
|
17
|
+
message = "Moved to top"
|
18
|
+
go_to 0
|
19
|
+
when "prev"
|
20
|
+
message = "Moved to previous"
|
21
|
+
position = config_read_position
|
22
|
+
go_to position + 1 if position < get_repo_length
|
23
|
+
when "bottom"
|
24
|
+
message = "Moved to bottom"
|
25
|
+
go_to get_repo_length
|
26
|
+
when "init"
|
27
|
+
message = init()
|
28
|
+
when "remove"
|
29
|
+
go_to 0
|
30
|
+
File.delete @current_path + CONFIG_FILE
|
31
|
+
message = "Gitnext Removed"
|
32
|
+
else
|
33
|
+
if args.to_s.empty?
|
34
|
+
message = "Moving to Next"
|
35
|
+
position = config_read_position
|
36
|
+
go_to position - 1 if position > 0
|
37
|
+
git_show = `git show --stat`.split("\n")
|
38
|
+
|
39
|
+
3.times { git_show.delete_at 1 }
|
40
|
+
git_show.pop
|
41
|
+
message += "\n" + git_show.compact.join("\n")
|
42
|
+
else
|
43
|
+
message = usage_message
|
44
|
+
end
|
45
|
+
end
|
46
|
+
else
|
47
|
+
case args
|
48
|
+
when "init"
|
49
|
+
message = init()
|
50
|
+
when "help"
|
51
|
+
message = usage_message
|
52
|
+
else
|
53
|
+
message = "GitNext not initialised"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
else
|
57
|
+
message = "Not a git directory\n" + usage_message
|
58
|
+
end
|
59
|
+
message
|
60
|
+
end
|
61
|
+
|
62
|
+
private
|
63
|
+
|
64
|
+
def self.init
|
65
|
+
if @git.status.changed.empty?
|
66
|
+
go_to get_repo_length
|
67
|
+
"GitNext initialised\nMoved to bottom"
|
68
|
+
else
|
69
|
+
"Cannot init with dirty repo"
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def self.config_save_position value
|
74
|
+
File.open(@current_path + CONFIG_FILE, "w") { |f| f.write value }
|
75
|
+
end
|
76
|
+
|
77
|
+
def self.config_read_position
|
78
|
+
File.read(@current_path + CONFIG_FILE).to_i
|
79
|
+
end
|
80
|
+
|
81
|
+
def self.get_repo_length
|
82
|
+
@git.gblob('master').log.map(&:sha).length - 1
|
83
|
+
end
|
84
|
+
|
85
|
+
def self.go_to position
|
86
|
+
@git.checkout "master#{"~#{position}" if position > 0}", "--force"
|
87
|
+
config_save_position position
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,129 @@
|
|
1
|
+
require "rspec"
|
2
|
+
require "git_next"
|
3
|
+
require "git"
|
4
|
+
|
5
|
+
describe GitNext do
|
6
|
+
|
7
|
+
let(:sample_dir) { '/tmp/git_next_sample' }
|
8
|
+
|
9
|
+
context "not in git repo" do
|
10
|
+
before do
|
11
|
+
FileUtils::rm_rf sample_dir if File.exists?(sample_dir)
|
12
|
+
Dir.mkdir sample_dir
|
13
|
+
end
|
14
|
+
|
15
|
+
it("should warn if not a git directory") { lambda { GitNext.run sample_dir }.should_not raise_error }
|
16
|
+
end
|
17
|
+
|
18
|
+
context "in a git repo" do
|
19
|
+
let(:file_1) { File.join(sample_dir, 'file_1') }
|
20
|
+
let(:file_2) { File.join(sample_dir, 'file_2') }
|
21
|
+
let(:gitnext_config) { File.join sample_dir, ".git", "gitnext.config" }
|
22
|
+
|
23
|
+
before(:each) do
|
24
|
+
FileUtils::rm_rf(sample_dir) if File.exists?(sample_dir)
|
25
|
+
|
26
|
+
Dir.mkdir sample_dir
|
27
|
+
@git = Git.init sample_dir
|
28
|
+
File.open(file_1, "w") { |f| f.write "a" }
|
29
|
+
@git.add(".")
|
30
|
+
@git.commit "commit #1"
|
31
|
+
File.open(file_1, "w") { |f| f.write "b" }
|
32
|
+
@git.add(".")
|
33
|
+
@git.commit "commit #2"
|
34
|
+
File.open(file_1, "w") { |f| f.write "c" }
|
35
|
+
File.open(file_2, "w") { |f| f.write "y" }
|
36
|
+
@git.add(".")
|
37
|
+
@git.commit "commit #3"
|
38
|
+
File.open(file_1, "w") { |f| f.write "d" }
|
39
|
+
File.open(file_2, "w") { |f| f.write "z" }
|
40
|
+
@git.add(".")
|
41
|
+
@git.commit "commit #4"
|
42
|
+
end
|
43
|
+
|
44
|
+
context "when init" do
|
45
|
+
it("should not create config file") { File.exists?(gitnext_config).should_not be_true }
|
46
|
+
end
|
47
|
+
|
48
|
+
context "dirty repo" do
|
49
|
+
before { File.open(file_1, "w") { |f| f.write "1" } }
|
50
|
+
it "should not init" do
|
51
|
+
GitNext.run sample_dir, "init"
|
52
|
+
File.exists?(gitnext_config).should_not be_true
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context "after init" do
|
57
|
+
before { GitNext.run sample_dir, "init" }
|
58
|
+
context "clean repo" do
|
59
|
+
it("should go to last commit") { File.read(file_1).should == "a" }
|
60
|
+
it("should create config file") { File.exists?(gitnext_config).should be_true }
|
61
|
+
it("should create have value of 4") { File.read(gitnext_config).should == "3" }
|
62
|
+
end
|
63
|
+
context "after gitnext initialised" do
|
64
|
+
before { GitNext.run sample_dir }
|
65
|
+
it("should go to next version") { File.read(file_1).should == "b" }
|
66
|
+
it("config should have 2") { File.read(gitnext_config).should == "2" }
|
67
|
+
end
|
68
|
+
|
69
|
+
describe "remove" do
|
70
|
+
before { GitNext.run sample_dir, "remove" }
|
71
|
+
|
72
|
+
it("should remove gitnext config") { File.exists?(gitnext_config).should_not be_true }
|
73
|
+
it("should be at master") { File.read(file_1).should == "d" }
|
74
|
+
end
|
75
|
+
|
76
|
+
context "should not go past top" do
|
77
|
+
before do
|
78
|
+
GitNext.run(sample_dir, "top")
|
79
|
+
GitNext.run sample_dir
|
80
|
+
end
|
81
|
+
it("should be 0") { File.read(gitnext_config).should == "0" }
|
82
|
+
it("should be last commit") { File.read(file_1).should == "d" }
|
83
|
+
end
|
84
|
+
|
85
|
+
context "should not go past bottom" do
|
86
|
+
before do
|
87
|
+
GitNext.run sample_dir, "bottom"
|
88
|
+
GitNext.run sample_dir, "prev"
|
89
|
+
end
|
90
|
+
it("should be 3") { File.read(gitnext_config).should == "3" }
|
91
|
+
it("should be at first") { File.read(file_1).should == "a" }
|
92
|
+
end
|
93
|
+
|
94
|
+
context "top" do
|
95
|
+
before do
|
96
|
+
@git.checkout("master~2")
|
97
|
+
GitNext.run(sample_dir, "top")
|
98
|
+
end
|
99
|
+
|
100
|
+
it("should go to top commit") { File.read(gitnext_config).should == "0" }
|
101
|
+
it("should be at master") { File.read(file_1).should == "d" }
|
102
|
+
end
|
103
|
+
describe "bottom" do
|
104
|
+
before do
|
105
|
+
@git.checkout("master~1")
|
106
|
+
GitNext.run(sample_dir, "bottom")
|
107
|
+
end
|
108
|
+
|
109
|
+
it("should go to bottom commit") { File.read(gitnext_config).should == "3" }
|
110
|
+
it("should be at last") { File.read(file_1).should == "a" }
|
111
|
+
end
|
112
|
+
describe "previous (prev)" do
|
113
|
+
before do
|
114
|
+
GitNext.run sample_dir, "top"
|
115
|
+
end
|
116
|
+
context "clean repo" do
|
117
|
+
before { GitNext.run sample_dir, "prev" }
|
118
|
+
it("should go to bottom commit") { File.read(gitnext_config).should == "1" }
|
119
|
+
it("should be at last") { File.read(file_1).should == "c" }
|
120
|
+
end
|
121
|
+
context "unclean repo" do
|
122
|
+
before { File.open(file_1, "w") { |f| f.write "1" } }
|
123
|
+
it("should not fail if repo unclean") { lambda { GitNext.run sample_dir }.should_not raise_error }
|
124
|
+
end
|
125
|
+
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
metadata
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gitnext
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 25
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Nigel
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-06-12 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: rspec
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ~>
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 11
|
29
|
+
segments:
|
30
|
+
- 2
|
31
|
+
- 1
|
32
|
+
- 0
|
33
|
+
version: 2.1.0
|
34
|
+
type: :development
|
35
|
+
version_requirements: *id001
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: git
|
38
|
+
prerelease: false
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - "="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
hash: 21
|
45
|
+
segments:
|
46
|
+
- 1
|
47
|
+
- 2
|
48
|
+
- 5
|
49
|
+
version: 1.2.5
|
50
|
+
type: :runtime
|
51
|
+
version_requirements: *id002
|
52
|
+
description:
|
53
|
+
email:
|
54
|
+
- nigelr@brisbanerails.com
|
55
|
+
executables:
|
56
|
+
- gitnext
|
57
|
+
extensions: []
|
58
|
+
|
59
|
+
extra_rdoc_files: []
|
60
|
+
|
61
|
+
files:
|
62
|
+
- spec/git_next_spec.rb
|
63
|
+
- lib/git_next.rb
|
64
|
+
- bin/gitnext
|
65
|
+
- gitnext.gemspec
|
66
|
+
homepage: http://github.com/nigelr/gitnext
|
67
|
+
licenses: []
|
68
|
+
|
69
|
+
post_install_message:
|
70
|
+
rdoc_options: []
|
71
|
+
|
72
|
+
require_paths:
|
73
|
+
- lib
|
74
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
75
|
+
none: false
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
hash: 3
|
80
|
+
segments:
|
81
|
+
- 0
|
82
|
+
version: "0"
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
hash: 3
|
89
|
+
segments:
|
90
|
+
- 0
|
91
|
+
version: "0"
|
92
|
+
requirements: []
|
93
|
+
|
94
|
+
rubyforge_project:
|
95
|
+
rubygems_version: 1.8.5
|
96
|
+
signing_key:
|
97
|
+
specification_version: 3
|
98
|
+
summary: Simple method to move forward or backwards through a git repo
|
99
|
+
test_files: []
|
100
|
+
|