git-helpers 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 82e6414a87935574c740f9d98767652b1c025da8
4
- data.tar.gz: 5f015b8462fbba630f4d3707d867f0f2a351d829
3
+ metadata.gz: 4981c208c8a78f9d127ae0eadb4d094aa5d22527
4
+ data.tar.gz: d68a8861b6012bb68104ed6f51b68ff32c0ac876
5
5
  SHA512:
6
- metadata.gz: 92f619ab95515a29e3d0e4b75b824784ebb85dcff7dc6c5e0d9e159383ccb0d51249dc8865b7372152c4c09566106762c2cd45e01357ad14c6abefdd76081200
7
- data.tar.gz: 1bfcc829bb713f1da03ad088dc367a681fcf1ec0b192cedbb426b0576a534cf343a7fc9673859a67ba3d46285d9070bae2b1b49c68c4d9648376d726628906bc
6
+ metadata.gz: 003a486979b01520f36627e2441d4f0c5e2a75ddd016776265bdc3c2e85ac4f886817130f5fe83b9edbd477dc0fc22abb8fc07b17d595c5854c50d76452edcbd
7
+ data.tar.gz: 3f9100bb1444f1cfbdb0477edc42b3a7833ec88cf5401cc42f8ecba58a7ff57cc53d25efa449bb35e4ebc87d8f6c5898baf150cbdf81df8dc0663679700ec620
data/README.md CHANGED
@@ -22,6 +22,14 @@ Running `git update` will pull down the latest changes for your current branch
22
22
  from the upstream remote (or origin if you don't have an upstream), and pushes
23
23
  the changes to your origin (or not at all if it was pulled from origin).
24
24
 
25
+ ### Browse
26
+ Running `git browse` will open the current repo in your web browser to the repository
27
+ page at the current working branch. You can specify the remote if you wish to
28
+ browse a different one in the format `git browse [remote]`. If you wish to view a
29
+ specific branch/tag/commit then you can specify the tree after `remote` in the
30
+ format `git browse [remote] [tree]`.
31
+ *Note: To use a commit as a tree you must use the full commit hash*
32
+
25
33
  ## Development
26
34
 
27
35
  After checking out the repo, run `bundle` to install dependencies. Then, run `bundle exec rake spec` to run the tests.
data/exe/git-browse ADDED
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env ruby
2
+ require 'git/helpers'
3
+ require 'optparse'
4
+
5
+ OptionParser.new do |opts|
6
+ opts.banner = "Git-Helpers git browse\n"\
7
+ "Opens the default browser to the optionally specified remote (default 'origin'), at the optional branch/tree/commit\n"\
8
+ 'Usage: git browse [remote] [branch/tree/commit]'
9
+ opts.on_tail '-h', '--help', 'Shows this help message' do
10
+ puts opts
11
+ exit 0
12
+ end
13
+ opts.on_tail '-v', '--version', 'Shows the version of git-helpers' do
14
+ puts "Git-Helpers version #{Git::Helpers::VERSION}"
15
+ exit 0
16
+ end
17
+ end.parse!
18
+
19
+ remote = ARGV.shift unless ARGV.empty?
20
+ tree = ARGV.shift unless ARGV.empty?
21
+
22
+ if remote.nil?
23
+ Git::Helpers.browse
24
+ elsif tree.nil?
25
+ Git::Helpers.browse Dir.pwd, remote
26
+ else
27
+ Git::Helpers.browse Dir.pwd, remote, tree
28
+ end
@@ -0,0 +1,24 @@
1
+ require 'git/helpers/utils'
2
+ module Git
3
+ # Provides a set of helper functions to make Git life easier
4
+ module Helpers
5
+ require 'git'
6
+ require 'launchy'
7
+
8
+ # Opens the default web browser to the specified repositorys page based on
9
+ # the the specified remote, and tree
10
+ # @param repo_dir [String] Directory of the git repo to browse, defaults to current working dir
11
+ # @param remote_name [String] Name of the remote to browse, defaults to origin
12
+ # @param tree [String] Tree to browse, can be a branch name, tag, or commit hash
13
+ def self.browse(repo_dir = Dir.pwd, remote_name = 'origin', tree = nil)
14
+ repo = Git.open(repo_dir)
15
+ raise "#{remote_name} is not a known remote" unless Utils.remote? repo, remote_name
16
+ remote = Utils.remotes_hash(repo)[remote_name]
17
+ tree ||= repo.current_branch
18
+ url = remote.url.chomp('.git')
19
+ url = Utils.transform_url(url)
20
+ url << "/tree/#{tree}"
21
+ Launchy.open url
22
+ end
23
+ end
24
+ end
@@ -10,6 +10,29 @@ module Git
10
10
  def self.remote?(repo, remote)
11
11
  repo.remotes.map(&:name).include?(remote)
12
12
  end
13
+
14
+ # Get a hash of remotes keyed to their name
15
+ # @param repo [Git::Base] Repository to get the remotes for
16
+ # @return [Hash{String => Git::Remote}] A hash of remotes
17
+ def self.remotes_hash(repo)
18
+ Hash[repo.remotes.map { |r| [r.name, r] }]
19
+ end
20
+
21
+ # Takes a url from a git remote and transforms it into an normal url with
22
+ # the desired scheme
23
+ # @param url [String] Url to transform
24
+ # @param scheme [String] What scheme the transformed Url will use, https (default), or http
25
+ # @return [String] A transformed Url
26
+ def self.transform_url(url, scheme = 'https')
27
+ # if git ssh url
28
+ if /^git@/ === url
29
+ url.gsub(/^git@(.*):/, scheme + '://\1/')
30
+ elsif %r{^git://} === url
31
+ url.gsub(/^git/, scheme)
32
+ else
33
+ url
34
+ end
35
+ end
13
36
  end
14
37
  end
15
38
  end
@@ -1,5 +1,5 @@
1
1
  module Git
2
2
  module Helpers
3
- VERSION = '0.2.1'.freeze
3
+ VERSION = '0.3.0'.freeze
4
4
  end
5
5
  end
data/lib/git/helpers.rb CHANGED
@@ -1,2 +1,3 @@
1
1
  require 'git/helpers/version'
2
2
  require 'git/helpers/update'
3
+ require 'git/helpers/browse'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git-helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kierran McPherson
@@ -156,6 +156,7 @@ description: |2
156
156
  email:
157
157
  - kierranm@gmail.com
158
158
  executables:
159
+ - git-browse
159
160
  - git-update
160
161
  extensions: []
161
162
  extra_rdoc_files: []
@@ -168,9 +169,11 @@ files:
168
169
  - LICENSE.txt
169
170
  - README.md
170
171
  - Rakefile
172
+ - exe/git-browse
171
173
  - exe/git-update
172
174
  - git-helpers.gemspec
173
175
  - lib/git/helpers.rb
176
+ - lib/git/helpers/browse.rb
174
177
  - lib/git/helpers/update.rb
175
178
  - lib/git/helpers/utils.rb
176
179
  - lib/git/helpers/version.rb