git-it 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +21 -4
- data/bin/git-it +26 -8
- data/lib/git-it/commander.rb +176 -118
- data/lib/git-it/link_generator.rb +35 -0
- data/lib/git-it/version.rb +1 -1
- data/lib/git-it.rb +4 -3
- metadata +3 -2
data/README.rdoc
CHANGED
@@ -18,9 +18,17 @@ Might not need sudo depending on your setup. To install as /usr/bin/git-it thoug
|
|
18
18
|
|
19
19
|
== Use
|
20
20
|
|
21
|
-
Open
|
21
|
+
Open branch
|
22
22
|
|
23
|
-
git it
|
23
|
+
git it opened #=> https://github.com/more-ron/git-it/tree/gh-pages
|
24
|
+
|
25
|
+
Compare branches
|
26
|
+
|
27
|
+
git it compared #=> https://github.com/more-ron/git-it/compare/master...gh-pages
|
28
|
+
|
29
|
+
Issue a pull request
|
30
|
+
|
31
|
+
git it pulled #=> https://github.com/more-ron/git-it/pull/new/more-ron:master...gh-pages
|
24
32
|
|
25
33
|
|
26
34
|
|
@@ -40,9 +48,18 @@ You will need to know where git-it got installed. To do that execute the followi
|
|
40
48
|
|
41
49
|
[Parameters]
|
42
50
|
|
43
|
-
get it opened
|
51
|
+
get it opened:
|
52
|
+
--path=$REPO --sha=$SHA opened
|
53
|
+
|
54
|
+
get it compared:
|
55
|
+
--path=$REPO --sha=$SHA compared
|
56
|
+
get it compared to release:
|
57
|
+
--path=$REPO --sha=$SHA compared --to=release
|
44
58
|
|
45
|
-
|
59
|
+
get it pulled:
|
60
|
+
--path=$REPO --sha=$SHA pulled
|
61
|
+
get it pulled to release:
|
62
|
+
--path=$REPO --sha=$SHA pulled --to=release
|
46
63
|
|
47
64
|
|
48
65
|
|
data/bin/git-it
CHANGED
@@ -34,20 +34,35 @@ default_value false
|
|
34
34
|
# = Commands =
|
35
35
|
# ============
|
36
36
|
|
37
|
-
desc 'Opens current branch
|
37
|
+
desc 'Opens current branch.'
|
38
|
+
command :opened do |c|
|
39
|
+
c.action do |global_options, options, args|
|
40
|
+
GitIt::Commander.new( global_options ).open( args, options )
|
41
|
+
end
|
42
|
+
end
|
38
43
|
|
39
|
-
|
44
|
+
desc 'Compares current branch to...'
|
45
|
+
command :compared do |c|
|
40
46
|
|
41
|
-
c.desc '
|
42
|
-
c.default_value '
|
43
|
-
c.flag :
|
47
|
+
c.desc 'Name of the branch to compare to'
|
48
|
+
c.default_value 'master'
|
49
|
+
c.flag :to
|
44
50
|
|
45
|
-
c.action do |global_options,options,args|
|
46
|
-
GitIt::Commander.new(global_options).
|
51
|
+
c.action do |global_options, options, args|
|
52
|
+
GitIt::Commander.new( global_options ).compare( args, options )
|
47
53
|
end
|
48
54
|
end
|
49
55
|
|
50
|
-
|
56
|
+
desc 'Issue pull request for current branch to...'
|
57
|
+
command :pulled do |c|
|
58
|
+
|
59
|
+
c.desc 'Name of the branch to be pulled into'
|
60
|
+
c.default_value 'master'
|
61
|
+
c.flag :to
|
62
|
+
|
63
|
+
c.action do |global_options, options, args|
|
64
|
+
GitIt::Commander.new( global_options ).pull( args, options )
|
65
|
+
end
|
51
66
|
end
|
52
67
|
|
53
68
|
# ====================
|
@@ -75,4 +90,7 @@ on_error do |exception|
|
|
75
90
|
true
|
76
91
|
end
|
77
92
|
|
93
|
+
class Object # :nodoc:
|
94
|
+
end
|
95
|
+
|
78
96
|
exit run(ARGV)
|
data/lib/git-it/commander.rb
CHANGED
@@ -1,149 +1,207 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
1
|
+
module GitIt
|
2
|
+
# Grand central station for git it commands
|
3
|
+
class Commander
|
4
|
+
|
5
|
+
# current git repository
|
6
|
+
attr_reader :repository
|
7
|
+
|
8
|
+
# current git object
|
9
|
+
attr_reader :git_object
|
10
|
+
|
11
|
+
# [global options]
|
12
|
+
#
|
13
|
+
# --help:: Show this message
|
14
|
+
# -p, --path=path:: repository path (default: {{present_working_directory}})
|
15
|
+
# -s, --sha=sha:: SHA1 (default: {{current_head}})
|
16
|
+
#
|
17
|
+
# [sample usage]
|
18
|
+
#
|
19
|
+
# Open present working directory's repository branch:
|
20
|
+
# git it opened
|
21
|
+
#
|
22
|
+
# Open specified repository in the path:
|
23
|
+
# git it --path=the/path/to/the/repo opened
|
24
|
+
#
|
25
|
+
# Open specified sha1:
|
26
|
+
# git it --sha=50m35ha1 opened
|
27
|
+
#
|
28
|
+
# Open specified repository in the path and sha1:
|
29
|
+
# git it --path=the/path/to/the/repo --sha=50m35ha1 opened
|
30
|
+
#
|
31
|
+
def initialize(options)
|
32
|
+
@global_options = options
|
33
|
+
@repository = Rugged::Repository.new( get_path(options[:path]) )
|
34
|
+
@git_object = get_object( options[:sha] )
|
35
|
+
@test_mode = options[:test]
|
36
|
+
|
37
|
+
@link_generator = LinkGenerator.new( @repository.config["remote.origin.url"] )
|
38
|
+
end
|
21
39
|
|
22
40
|
|
23
41
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
# [get it opened in the web]
|
29
|
-
#
|
30
|
-
# Opens closest branch in the web.
|
31
|
-
#
|
32
|
-
# [commands]
|
33
|
-
#
|
34
|
-
# Open present working directory's repository and head in the web:
|
35
|
-
# git it opened_in_the_web
|
36
|
-
#
|
37
|
-
# Open specified repository in the path:
|
38
|
-
# git it --path=the/path/to/the/repo opened_in_the_web
|
39
|
-
#
|
40
|
-
# Open specified sha1:
|
41
|
-
# git it --sha=50m35ha1 opened_in_the_web
|
42
|
-
#
|
43
|
-
# Open specified repository in the path and sha1:
|
44
|
-
# git it --path=the/path/to/the/repo --sha=50m35ha1 opened_in_the_web
|
45
|
-
#
|
46
|
-
# [notes]
|
47
|
-
#
|
48
|
-
# * Currently only supports GitHub.com
|
49
|
-
#
|
50
|
-
def open_in_the_web(args, options)
|
51
|
-
closest_branch = closest_remote_branch || closest_local_branch
|
52
|
-
|
53
|
-
if closest_branch
|
54
|
-
remote_origin_url = repository.config["remote.origin.url"]
|
55
|
-
#=> git@github.com:more-ron/git-it.git
|
56
|
-
|
57
|
-
github_link = remote_origin_url.gsub("git@github.com:", "https://github.com/")
|
58
|
-
#=> https://github.com/more-ron/git-it.git
|
59
|
-
|
60
|
-
branch_name = closest_branch.name.gsub("origin/", "")
|
61
|
-
#=> origin/gh-pages => gh-pages
|
42
|
+
# ===========
|
43
|
+
# = Actions =
|
44
|
+
# ===========
|
62
45
|
|
63
|
-
|
64
|
-
|
46
|
+
# [get it opened]
|
47
|
+
#
|
48
|
+
# Opens the current branch
|
49
|
+
#
|
50
|
+
# [sample usage]
|
51
|
+
#
|
52
|
+
# Open the current branch:
|
53
|
+
# git it opened
|
54
|
+
#
|
55
|
+
def open(args, options)
|
56
|
+
_closest_branch = closest_branch
|
65
57
|
|
66
|
-
|
67
|
-
|
58
|
+
if _closest_branch
|
59
|
+
branch_name = clean_branch_name_for( _closest_branch )
|
60
|
+
link = @link_generator.branch_link( branch_name )
|
68
61
|
|
69
|
-
|
70
|
-
|
71
|
-
|
62
|
+
launch link
|
63
|
+
else
|
64
|
+
fail "Could not find closest remote branch for sha: #{@git_object.oid.inspect}"
|
65
|
+
end
|
72
66
|
end
|
73
|
-
end
|
74
67
|
|
68
|
+
# [get it compared]
|
69
|
+
#
|
70
|
+
# Compares the current branch to another branch (default: master)
|
71
|
+
#
|
72
|
+
# [sample usage]
|
73
|
+
#
|
74
|
+
# Compare the current branch to master branch
|
75
|
+
# git it compared
|
76
|
+
#
|
77
|
+
# Compare the current branch to release branch
|
78
|
+
# git it compared --to=release
|
79
|
+
#
|
80
|
+
def compare(args, options)
|
81
|
+
_closest_branch = closest_branch
|
82
|
+
|
83
|
+
if _closest_branch
|
84
|
+
branch_name = clean_branch_name_for( _closest_branch )
|
85
|
+
link = @link_generator.compare_branches_link( branch_name, options[:to] || "master" )
|
86
|
+
|
87
|
+
launch link
|
88
|
+
else
|
89
|
+
fail "Could not find closest remote branch for sha: #{@git_object.oid.inspect}"
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
# [get it pulled]
|
94
|
+
#
|
95
|
+
# Issues a pull request of the current branch into another branch (default: master)
|
96
|
+
#
|
97
|
+
# [sample usage]
|
98
|
+
#
|
99
|
+
# Issue a pull request of the current branch into master branch
|
100
|
+
# git it pulled
|
101
|
+
#
|
102
|
+
# Issue a pull request of the current branch into release branch
|
103
|
+
# git it pulled --to=release
|
104
|
+
#
|
105
|
+
def pull(args, options)
|
106
|
+
_closest_branch = closest_branch
|
107
|
+
|
108
|
+
if _closest_branch
|
109
|
+
branch_name = clean_branch_name_for( _closest_branch )
|
110
|
+
link = @link_generator.pull_request_link( branch_name, options[:to] || "master" )
|
111
|
+
|
112
|
+
launch link
|
113
|
+
else
|
114
|
+
fail "Could not find closest remote branch for sha: #{@git_object.oid.inspect}"
|
115
|
+
end
|
116
|
+
end
|
75
117
|
|
76
118
|
|
77
|
-
# ============
|
78
|
-
# = Privates =
|
79
|
-
# ============
|
80
119
|
|
81
|
-
|
120
|
+
# ============
|
121
|
+
# = Privates =
|
122
|
+
# ============
|
82
123
|
|
83
|
-
|
84
|
-
path == "{{present_working_directory}}" ? Dir.pwd : path
|
85
|
-
end
|
124
|
+
private
|
86
125
|
|
87
|
-
|
88
|
-
|
89
|
-
repository.lookup( repository.head.target )
|
90
|
-
else
|
91
|
-
repository.lookup( sha )
|
126
|
+
def get_path(path)
|
127
|
+
path == "{{present_working_directory}}" ? Dir.pwd : path
|
92
128
|
end
|
93
|
-
end
|
94
129
|
|
95
|
-
|
96
|
-
|
97
|
-
|
130
|
+
def get_object(sha)
|
131
|
+
if sha == "{{current_head}}"
|
132
|
+
repository.lookup( repository.head.target )
|
133
|
+
else
|
134
|
+
repository.lookup( sha )
|
135
|
+
end
|
136
|
+
end
|
98
137
|
|
99
|
-
|
100
|
-
|
101
|
-
Rugged::Branch.lookup(@repository, branch_name, :remote)
|
138
|
+
def discover_repository(path)
|
139
|
+
Rugged::Repository.discover( path )
|
102
140
|
end
|
103
|
-
end
|
104
141
|
|
105
|
-
|
106
|
-
|
107
|
-
|
142
|
+
def remote_branches
|
143
|
+
@remote_branches ||= Rugged::Branch.each_name(repository, :remote).sort.collect do |branch_name|
|
144
|
+
Rugged::Branch.lookup(@repository, branch_name, :remote)
|
145
|
+
end
|
108
146
|
end
|
109
|
-
end
|
110
147
|
|
111
|
-
|
112
|
-
|
113
|
-
|
148
|
+
def local_branches
|
149
|
+
@local_branches ||= Rugged::Branch.each_name(repository, :local).sort.collect do |branch_name|
|
150
|
+
Rugged::Branch.lookup(@repository, branch_name)
|
151
|
+
end
|
114
152
|
end
|
115
|
-
end
|
116
153
|
|
117
|
-
|
118
|
-
|
119
|
-
|
154
|
+
def closest_remote_branch
|
155
|
+
remote_branches.min_by do |branch|
|
156
|
+
distance_in_objects(:from => branch.tip.oid, :to => @git_object.oid)
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
def closest_local_branch
|
161
|
+
local_branches.min_by do |branch|
|
162
|
+
distance_in_objects(:from => branch.tip.oid, :to => @git_object.oid)
|
163
|
+
end
|
120
164
|
end
|
121
|
-
end
|
122
165
|
|
123
|
-
|
124
|
-
|
125
|
-
|
166
|
+
def closest_branch
|
167
|
+
closest_remote_branch || closest_local_branch
|
168
|
+
end
|
126
169
|
|
127
|
-
|
128
|
-
|
170
|
+
def clean_branch_name_for( branch )
|
171
|
+
branch_name = branch.name.gsub("origin/", "")
|
172
|
+
#=> origin/gh-pages => gh-pages
|
129
173
|
|
130
|
-
|
131
|
-
|
132
|
-
walker.push(options[:to])
|
133
|
-
walker.hide(options[:from])
|
134
|
-
walker.count
|
135
|
-
end
|
174
|
+
branch_name = branch.target.gsub("refs/remotes/origin/", "") if branch_name == "HEAD"
|
175
|
+
#=> refs/remotes/origin/master => master
|
136
176
|
|
137
|
-
|
138
|
-
|
139
|
-
|
177
|
+
branch_name
|
178
|
+
end
|
179
|
+
|
180
|
+
def distance_in_objects(options = {})
|
181
|
+
normal_direction_value = _distance_in_objects(options)
|
182
|
+
opposite_direction_value = _distance_in_objects(:from => options[:to], :to => options[:from])
|
140
183
|
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
184
|
+
[normal_direction_value, opposite_direction_value].max
|
185
|
+
end
|
186
|
+
|
187
|
+
def _distance_in_objects(options = {})
|
188
|
+
walker = Rugged::Walker.new(repository)
|
189
|
+
walker.push(options[:to])
|
190
|
+
walker.hide(options[:from])
|
191
|
+
walker.count
|
192
|
+
end
|
193
|
+
|
194
|
+
def test_mode?
|
195
|
+
@test_mode
|
196
|
+
end
|
197
|
+
|
198
|
+
def launch(what)
|
199
|
+
if test_mode?
|
200
|
+
puts "Launchy.open( #{what.inspect} )"
|
201
|
+
else
|
202
|
+
Launchy.open( what )
|
203
|
+
end
|
146
204
|
end
|
147
|
-
end
|
148
205
|
|
206
|
+
end
|
149
207
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module GitIt
|
2
|
+
# Link generator compatible with GitHub like site UI
|
3
|
+
class LinkGenerator
|
4
|
+
|
5
|
+
# git@github.com:more-ron/git-it.git
|
6
|
+
attr_reader :repository_url
|
7
|
+
|
8
|
+
# all you need is the repository url
|
9
|
+
def initialize(repository_url)
|
10
|
+
@repository_url = repository_url
|
11
|
+
|
12
|
+
@repo = /^git@(?<site>.*):(?<user>.*)\/(?<proj>.*).git$/.match(@repository_url)
|
13
|
+
|
14
|
+
@site = @repo[:site]
|
15
|
+
@user = @repo[:user]
|
16
|
+
@proj = @repo[:proj]
|
17
|
+
end
|
18
|
+
|
19
|
+
# https://github.com/more-ron/git-it/tree/gh-pages
|
20
|
+
def branch_link(branch_name)
|
21
|
+
"https://#{@site}/#{@user}/#{@proj}/tree/#{branch_name}"
|
22
|
+
end
|
23
|
+
|
24
|
+
# https://github.com/more-ron/git-it/compare/master...gh-pages
|
25
|
+
def compare_branches_link(to, from = "master")
|
26
|
+
"https://#{@site}/#{@user}/#{@proj}/compare/#{from}...#{to}"
|
27
|
+
end
|
28
|
+
|
29
|
+
# https://github.com/more-ron/git-it/pull/new/more-ron:master...gh-pages
|
30
|
+
def pull_request_link(source, destination = "master")
|
31
|
+
"https://#{@site}/#{@user}/#{@proj}/pull/new/#{@user}:#{destination}...#{source}"
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
data/lib/git-it/version.rb
CHANGED
data/lib/git-it.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
|
-
require 'git-it/version
|
2
|
-
require 'git-it/global_helper
|
3
|
-
require 'git-it/commander
|
1
|
+
require 'git-it/version'
|
2
|
+
require 'git-it/global_helper'
|
3
|
+
require 'git-it/commander'
|
4
|
+
require 'git-it/link_generator'
|
4
5
|
|
5
6
|
# Add requires for other files you add to your project here, so
|
6
7
|
# you just need to require this one file in your bin file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: git-it
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -116,11 +116,12 @@ extra_rdoc_files:
|
|
116
116
|
- README.rdoc
|
117
117
|
- git-it.rdoc
|
118
118
|
files:
|
119
|
-
- bin/git-it
|
120
119
|
- lib/git-it/commander.rb
|
121
120
|
- lib/git-it/global_helper.rb
|
121
|
+
- lib/git-it/link_generator.rb
|
122
122
|
- lib/git-it/version.rb
|
123
123
|
- lib/git-it.rb
|
124
|
+
- bin/git-it
|
124
125
|
- README.rdoc
|
125
126
|
- git-it.rdoc
|
126
127
|
homepage: http://more-ron.github.com/git-it/
|