git-it 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +22 -0
- data/bin/git-it +71 -0
- data/git-it.rdoc +1 -0
- data/lib/git-it/controller.rb +88 -0
- data/lib/git-it/global_helper.rb +8 -0
- data/lib/git-it/version.rb +3 -0
- data/lib/git-it.rb +6 -0
- metadata +140 -0
data/README.rdoc
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
= git-it! get it?
|
2
|
+
|
3
|
+
Commands to help you git it.
|
4
|
+
|
5
|
+
Author:: Ronald Maravilla (mailto:more.ron.too@gmail.com)
|
6
|
+
License:: Undecided
|
7
|
+
|
8
|
+
== Install
|
9
|
+
|
10
|
+
gem install git-it
|
11
|
+
|
12
|
+
== Use
|
13
|
+
|
14
|
+
Open current branch in the web. Use it as an easy way to issue pull request in github.
|
15
|
+
|
16
|
+
git it opened_in_the_web
|
17
|
+
|
18
|
+
== Documentation
|
19
|
+
|
20
|
+
API Documentation is available {here}[http://more-ron.github.com/git-it/index.html]. Recommend starting with GitIt::Controller.
|
21
|
+
|
22
|
+
:include:git-it.rdoc
|
data/bin/git-it
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'gli'
|
4
|
+
require 'git-it'
|
5
|
+
|
6
|
+
include GLI::App
|
7
|
+
extend GitIt::GlobalHelper
|
8
|
+
|
9
|
+
program_desc 'Git it! Get it?'
|
10
|
+
|
11
|
+
version GitIt::VERSION
|
12
|
+
|
13
|
+
|
14
|
+
# ==================
|
15
|
+
# = Global Options =
|
16
|
+
# ==================
|
17
|
+
|
18
|
+
desc 'debug mode'
|
19
|
+
switch [:d,:debug]
|
20
|
+
|
21
|
+
desc 'SHA1'
|
22
|
+
default_value '{{current_head}}'
|
23
|
+
arg_name 'sha'
|
24
|
+
flag [:s,:sha]
|
25
|
+
|
26
|
+
|
27
|
+
# ============
|
28
|
+
# = Commands =
|
29
|
+
# ============
|
30
|
+
|
31
|
+
desc 'Opens current branch in web browser.'
|
32
|
+
|
33
|
+
command :opened_in_the_web do |c|
|
34
|
+
|
35
|
+
c.desc 'Site: auto | github'
|
36
|
+
c.default_value 'auto'
|
37
|
+
c.flag :site
|
38
|
+
|
39
|
+
c.action do |global_options,options,args|
|
40
|
+
GitIt::Controller.new(global_options).open_in_the_web(args, options)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
|
46
|
+
# ====================
|
47
|
+
# = Before and After =
|
48
|
+
# ====================
|
49
|
+
|
50
|
+
pre do |global,command,options,args|
|
51
|
+
# Pre logic here
|
52
|
+
# Return true to proceed; false to abort and not call the
|
53
|
+
# chosen command
|
54
|
+
# Use skips_pre before a command to skip this block
|
55
|
+
# on that command only
|
56
|
+
true
|
57
|
+
end
|
58
|
+
|
59
|
+
post do |global,command,options,args|
|
60
|
+
# Post logic here
|
61
|
+
# Use skips_post before a command to skip this
|
62
|
+
# block on that command only
|
63
|
+
end
|
64
|
+
|
65
|
+
on_error do |exception|
|
66
|
+
# Error logic here
|
67
|
+
# return false to skip default error handling
|
68
|
+
true
|
69
|
+
end
|
70
|
+
|
71
|
+
exit run(ARGV)
|
data/git-it.rdoc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
= git-it
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'rugged'
|
2
|
+
# require 'debugger'
|
3
|
+
|
4
|
+
# Grand central station for git it commands
|
5
|
+
class GitIt::Controller
|
6
|
+
|
7
|
+
attr_reader :repository
|
8
|
+
attr_reader :git_object
|
9
|
+
|
10
|
+
# Options::
|
11
|
+
# * --sha=sha1 - git object reference to work on
|
12
|
+
def initialize(options)
|
13
|
+
@repository = Rugged::Repository.new( discover_repository )
|
14
|
+
@git_object = get_object(options[:sha])
|
15
|
+
end
|
16
|
+
|
17
|
+
# ===========
|
18
|
+
# = Actions =
|
19
|
+
# ===========
|
20
|
+
|
21
|
+
# Command:: git it opened_in_the_web
|
22
|
+
def open_in_the_web(args, options)
|
23
|
+
remote_origin_url = repository.config["remote.origin.url"]
|
24
|
+
# => git@github.com:more-ron/git-it.git
|
25
|
+
|
26
|
+
github_link = remote_origin_url.gsub("git@github.com:", "https://github.com/")
|
27
|
+
# => https://github.com/more-ron/git-it.git
|
28
|
+
|
29
|
+
branch_name = closest_remote_branch.target.gsub("refs/remotes/origin/", "")
|
30
|
+
# refs/remotes/origin/master => master
|
31
|
+
|
32
|
+
github_link = github_link.gsub(".git", "/tree/#{ branch_name }")
|
33
|
+
# => https://github.com/more-ron/git-it/tree/master
|
34
|
+
|
35
|
+
`open #{ github_link }` # should use launchy in the future
|
36
|
+
end
|
37
|
+
|
38
|
+
# ============
|
39
|
+
# = Privates =
|
40
|
+
# ============
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def get_object(sha)
|
45
|
+
if sha == "{{current_head}}"
|
46
|
+
repository.lookup( repository.head.target )
|
47
|
+
else
|
48
|
+
repository.lookup( sha )
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def discover_repository
|
53
|
+
Rugged::Repository.discover( Dir.pwd )
|
54
|
+
end
|
55
|
+
|
56
|
+
def remote_branches
|
57
|
+
@remote_branches ||= Rugged::Branch.each_name(repository, :remote).sort.collect do |branch_name|
|
58
|
+
Rugged::Branch.lookup(@repository, branch_name, :remote)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def local_branches
|
63
|
+
@local_branches ||= Rugged::Branch.each_name(repository, :local).sort.collect do |branch_name|
|
64
|
+
Rugged::Branch.lookup(@repository, branch_name)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def closest_remote_branch
|
69
|
+
remote_branches.min_by do |branch|
|
70
|
+
distance_in_object(:from => branch.tip.oid, :to => @git_object.oid)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def distance_in_object(options = {})
|
75
|
+
normal_direction_value = _distance_in_object(options)
|
76
|
+
opposite_direction_value = _distance_in_object(:from => options[:to], :to => options[:from])
|
77
|
+
|
78
|
+
[normal_direction_value, opposite_direction_value].max
|
79
|
+
end
|
80
|
+
|
81
|
+
def _distance_in_object(options = {})
|
82
|
+
walker = Rugged::Walker.new(repository)
|
83
|
+
walker.push(options[:to])
|
84
|
+
walker.hide(options[:from])
|
85
|
+
walker.count
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
data/lib/git-it.rb
ADDED
metadata
ADDED
@@ -0,0 +1,140 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: git-it
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.4
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- MoreRon
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-02-15 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rdoc
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: aruba
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: gli
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - '='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 2.5.4
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - '='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 2.5.4
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: rugged
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ~>
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 0.17.0.b7
|
86
|
+
type: :runtime
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ~>
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: 0.17.0.b7
|
94
|
+
description:
|
95
|
+
email: more.ron.too@gmail.com
|
96
|
+
executables:
|
97
|
+
- git-it
|
98
|
+
extensions: []
|
99
|
+
extra_rdoc_files:
|
100
|
+
- README.rdoc
|
101
|
+
- git-it.rdoc
|
102
|
+
files:
|
103
|
+
- bin/git-it
|
104
|
+
- lib/git-it/controller.rb
|
105
|
+
- lib/git-it/global_helper.rb
|
106
|
+
- lib/git-it/version.rb
|
107
|
+
- lib/git-it.rb
|
108
|
+
- README.rdoc
|
109
|
+
- git-it.rdoc
|
110
|
+
homepage: http://more-ron.github.com/git-it/
|
111
|
+
licenses: []
|
112
|
+
post_install_message:
|
113
|
+
rdoc_options:
|
114
|
+
- --title
|
115
|
+
- git-it
|
116
|
+
- --main
|
117
|
+
- README.rdoc
|
118
|
+
- -ri
|
119
|
+
require_paths:
|
120
|
+
- lib
|
121
|
+
- lib
|
122
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
123
|
+
none: false
|
124
|
+
requirements:
|
125
|
+
- - ! '>='
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '0'
|
128
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
130
|
+
requirements:
|
131
|
+
- - ! '>='
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
requirements: []
|
135
|
+
rubyforge_project:
|
136
|
+
rubygems_version: 1.8.25
|
137
|
+
signing_key:
|
138
|
+
specification_version: 3
|
139
|
+
summary: Commands to help you git it.
|
140
|
+
test_files: []
|