git-it 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -1,22 +1,71 @@
1
1
  = git-it! get it?
2
2
 
3
+ {<img src="https://travis-ci.org/more-ron/git-it.png" />}[https://travis-ci.org/more-ron/git-it]
4
+
5
+ == Describe
6
+
3
7
  Commands to help you git it.
4
8
 
5
- Author:: Ronald Maravilla (mailto:more.ron.too@gmail.com)
6
- License:: Undecided
9
+
7
10
 
8
11
  == Install
9
12
 
10
- gem install git-it
13
+ Might not need sudo depending on your setup. To install as /usr/bin/git-it though you'll need sudo.
14
+
15
+ sudo gem install git-it #=> install git-it gem
16
+
17
+
11
18
 
12
19
  == Use
13
20
 
14
21
  Open current branch in the web. Use it as an easy way to issue pull request in github.
15
22
 
16
- git it opened_in_the_web
23
+ git it opened_in_the_web #=> open https://github.com/more-ron/git-it/tree/master
24
+
25
+
26
+
27
+ == Integrate with {SourceTree}[http://www.sourcetreeapp.com/]
28
+
29
+ Read instruction on how to add custom action {here}[http://blog.sourcetreeapp.com/2012/02/08/custom-actions-more-power-to-you/].
30
+
31
+ You will need to know where git-it got installed. To do that execute the following:
32
+
33
+ which git-it #=> /usr/bin/git-it
34
+
35
+ [Script to run]
36
+
37
+ Based on the result from above set the script to:
38
+
39
+ /usr/bin/git-it
17
40
 
18
- == Documentation
41
+ [Parameters]
42
+
43
+ get it opened in the web:
44
+
45
+ --path=$REPO --sha=$SHA opened_in_the_web
46
+
47
+
48
+
49
+ == Document
19
50
 
20
51
  API Documentation is available {here}[http://more-ron.github.com/git-it/index.html]. Recommend starting with GitIt::Commander.
21
52
 
53
+
54
+
55
+ Author:: {Ronald Maravilla}[http://about.me/ronald.maravilla]
56
+ Copyright:: Copyright © 2013 by Ronald Maravilla
57
+ License::
58
+
59
+ {MIT}[http://opensource.org/licenses/MIT]
60
+
61
+ Copyright (c) 2013 Ronald Maravilla
62
+
63
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
64
+
65
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
66
+
67
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
68
+
69
+
70
+
22
71
  :include:git-it.rdoc
data/bin/git-it CHANGED
@@ -2,23 +2,21 @@
2
2
 
3
3
  require 'gli'
4
4
  require 'git-it'
5
+ require 'rugged'
6
+ require 'launchy'
5
7
 
6
- include GLI::App
7
8
  extend GitIt::GlobalHelper
9
+ include GLI::App
8
10
 
9
11
  program_desc 'Git it! Get it?'
10
12
 
11
13
  version GitIt::VERSION
12
14
 
13
-
14
15
  # ==================
15
16
  # = Global Options =
16
17
  # ==================
17
18
 
18
- # desc 'debug mode'
19
- # switch [:d,:debug]
20
-
21
- desc 'repository path'
19
+ desc 'Repository path'
22
20
  default_value '{{present_working_directory}}'
23
21
  arg_name 'path'
24
22
  flag [:p,:path]
@@ -28,6 +26,9 @@ default_value '{{current_head}}'
28
26
  arg_name 'sha'
29
27
  flag [:s,:sha]
30
28
 
29
+ desc 'Test mode'
30
+ switch [:t,:test]
31
+ default_value false
31
32
 
32
33
  # ============
33
34
  # = Commands =
@@ -46,7 +47,8 @@ command :opened_in_the_web do |c|
46
47
  end
47
48
  end
48
49
 
49
-
50
+ class Object # :nodoc:
51
+ end
50
52
 
51
53
  # ====================
52
54
  # = Before and After =
@@ -1,48 +1,79 @@
1
- require 'rugged'
2
- # require 'debugger'
3
-
4
1
  # Grand central station for git it commands
5
2
  class GitIt::Commander
6
3
 
4
+ # current git repository
7
5
  attr_reader :repository
6
+
7
+ # current git object
8
8
  attr_reader :git_object
9
9
 
10
- # Global Options::
11
- # * --help - Show this message
12
- # * -p, --path=path - repository path (default: {{present_working_directory}})
13
- # * -s, --sha=sha - SHA1 (default: {{current_head}})
14
- # * --version - Show gem's version
10
+ # [global options]
11
+ # --help:: Show this message
12
+ # -p, --path=path:: repository path (default: {{present_working_directory}})
13
+ # -s, --sha=sha:: SHA1 (default: {{current_head}})
14
+ # --version:: Show gem's version
15
15
  def initialize(options)
16
16
  @global_options = options
17
17
  @repository = Rugged::Repository.new( get_path(options[:path]) )
18
18
  @git_object = get_object( options[:sha] )
19
+ @test_mode = options[:test]
19
20
  end
20
21
 
21
22
 
23
+
22
24
  # ===========
23
25
  # = Actions =
24
26
  # ===========
25
27
 
26
- # Command:: git it opened_in_the_web
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
+ #
27
50
  def open_in_the_web(args, options)
28
- remote_origin_url = repository.config["remote.origin.url"]
29
- # => git@github.com:more-ron/git-it.git
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
30
59
 
31
- github_link = remote_origin_url.gsub("git@github.com:", "https://github.com/")
32
- # => https://github.com/more-ron/git-it.git
60
+ branch_name = closest_branch.name.gsub("origin/", "")
61
+ #=> origin/gh-pages => gh-pages
33
62
 
34
- branch_name = closest_remote_branch.name.gsub("origin/", "")
35
- # origin/gh-pages => gh-pages
36
- branch_name = closest_remote_branch.target.gsub("refs/remotes/origin/", "") if branch_name == "HEAD"
37
- # refs/remotes/origin/master => master
63
+ branch_name = closest_remote_branch.target.gsub("refs/remotes/origin/", "") if branch_name == "HEAD"
64
+ #=> refs/remotes/origin/master => master
38
65
 
39
- github_link = github_link.gsub(".git", "/tree/#{ branch_name }")
40
- # => https://github.com/more-ron/git-it/tree/master
66
+ github_link = github_link.gsub(".git", "/tree/#{ branch_name }")
67
+ #=> https://github.com/more-ron/git-it/tree/master
41
68
 
42
- `open #{ github_link }` # should use launchy in the future
69
+ launch github_link
70
+ else
71
+ fail "Could not find closest remote branch for sha: #{@git_object.oid.inspect}"
72
+ end
43
73
  end
44
74
 
45
75
 
76
+
46
77
  # ============
47
78
  # = Privates =
48
79
  # ============
@@ -79,22 +110,40 @@ class GitIt::Commander
79
110
 
80
111
  def closest_remote_branch
81
112
  remote_branches.min_by do |branch|
82
- distance_in_object(:from => branch.tip.oid, :to => @git_object.oid)
113
+ distance_in_objects(:from => branch.tip.oid, :to => @git_object.oid)
83
114
  end
84
115
  end
85
116
 
86
- def distance_in_object(options = {})
87
- normal_direction_value = _distance_in_object(options)
88
- opposite_direction_value = _distance_in_object(:from => options[:to], :to => options[:from])
117
+ def closest_local_branch
118
+ local_branches.min_by do |branch|
119
+ distance_in_objects(:from => branch.tip.oid, :to => @git_object.oid)
120
+ end
121
+ end
122
+
123
+ def distance_in_objects(options = {})
124
+ normal_direction_value = _distance_in_objects(options)
125
+ opposite_direction_value = _distance_in_objects(:from => options[:to], :to => options[:from])
89
126
 
90
127
  [normal_direction_value, opposite_direction_value].max
91
128
  end
92
129
 
93
- def _distance_in_object(options = {})
130
+ def _distance_in_objects(options = {})
94
131
  walker = Rugged::Walker.new(repository)
95
132
  walker.push(options[:to])
96
133
  walker.hide(options[:from])
97
134
  walker.count
98
135
  end
99
136
 
137
+ def test_mode?
138
+ @test_mode
139
+ end
140
+
141
+ def launch(what)
142
+ if test_mode?
143
+ puts "Launchy.open( #{what.inspect} )"
144
+ else
145
+ Launchy.open( what )
146
+ end
147
+ end
148
+
100
149
  end
@@ -1,6 +1,8 @@
1
+ # Global helper to make it easier to git
1
2
  module GitIt::GlobalHelper
2
3
 
3
- # Prints "I don't git-it. That command made no sense."
4
+ # [I don't get it]
5
+ # Raises "I don't git-it. That command made no sense."
4
6
  def i_dont_git_it
5
7
  raise "I don't git-it. That command made no sense."
6
8
  end
@@ -1,3 +1,6 @@
1
+ # Command line interface to git it
1
2
  module GitIt
2
- VERSION = '0.0.6'
3
+
4
+ # Current git-it version
5
+ VERSION = '0.0.7'
3
6
  end
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.6
4
+ version: 0.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-16 00:00:00.000000000 Z
12
+ date: 2013-02-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -60,45 +60,45 @@ dependencies:
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  - !ruby/object:Gem::Dependency
63
- name: debugger
63
+ name: gli
64
64
  requirement: !ruby/object:Gem::Requirement
65
65
  none: false
66
66
  requirements:
67
- - - ! '>='
67
+ - - ~>
68
68
  - !ruby/object:Gem::Version
69
- version: '0'
70
- type: :development
69
+ version: 2.5.4
70
+ type: :runtime
71
71
  prerelease: false
72
72
  version_requirements: !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
75
- - - ! '>='
75
+ - - ~>
76
76
  - !ruby/object:Gem::Version
77
- version: '0'
77
+ version: 2.5.4
78
78
  - !ruby/object:Gem::Dependency
79
- name: gli
79
+ name: rugged
80
80
  requirement: !ruby/object:Gem::Requirement
81
81
  none: false
82
82
  requirements:
83
- - - '='
83
+ - - ~>
84
84
  - !ruby/object:Gem::Version
85
- version: 2.5.4
85
+ version: 0.17.0.b7
86
86
  type: :runtime
87
87
  prerelease: false
88
88
  version_requirements: !ruby/object:Gem::Requirement
89
89
  none: false
90
90
  requirements:
91
- - - '='
91
+ - - ~>
92
92
  - !ruby/object:Gem::Version
93
- version: 2.5.4
93
+ version: 0.17.0.b7
94
94
  - !ruby/object:Gem::Dependency
95
- name: rugged
95
+ name: launchy
96
96
  requirement: !ruby/object:Gem::Requirement
97
97
  none: false
98
98
  requirements:
99
99
  - - ~>
100
100
  - !ruby/object:Gem::Version
101
- version: 0.17.0.b7
101
+ version: 2.2.0
102
102
  type: :runtime
103
103
  prerelease: false
104
104
  version_requirements: !ruby/object:Gem::Requirement
@@ -106,7 +106,7 @@ dependencies:
106
106
  requirements:
107
107
  - - ~>
108
108
  - !ruby/object:Gem::Version
109
- version: 0.17.0.b7
109
+ version: 2.2.0
110
110
  description:
111
111
  email: more.ron.too@gmail.com
112
112
  executables: