git-helpers 0.3.0 → 0.4.0
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.
- checksums.yaml +4 -4
- data/README.md +12 -1
- data/exe/git-pr +40 -0
- data/lib/git/helpers/pull_request.rb +28 -0
- data/lib/git/helpers/utils.rb +20 -0
- data/lib/git/helpers/version.rb +1 -1
- data/lib/git/helpers.rb +2 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3c3aae4c9f77059eeb841e6a6342a9292616c3c5
|
4
|
+
data.tar.gz: 41804526c500c86e32371b84ec35754300abc2a6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c89be32c4173474ed8c978f2212be9b4b1e55c1c7803fc2612790831e8ca1270c108c13ff46b3cfcd9348532fab8a541db948ad48786235609e5305f03281e42
|
7
|
+
data.tar.gz: bd3fc87c14083b2322c2c7c57c53218d7c25ee656681983a0f751c2eeda9e2f121b8720330a375f1d9abc7c0180ee4a413d62c443c7b00253f0c2e9b2a1b902f
|
data/README.md
CHANGED
@@ -28,7 +28,18 @@ page at the current working branch. You can specify the remote if you wish to
|
|
28
28
|
browse a different one in the format `git browse [remote]`. If you wish to view a
|
29
29
|
specific branch/tag/commit then you can specify the tree after `remote` in the
|
30
30
|
format `git browse [remote] [tree]`.
|
31
|
-
*Note: To use a commit as a tree you must use the full commit hash*
|
31
|
+
*Note: To use a commit as a tree you must use the full commit hash*
|
32
|
+
|
33
|
+
### PR (Pull Request)
|
34
|
+
Running `git pr` or one of its other forms will open a new pull request window
|
35
|
+
in your default web browser.
|
36
|
+
*Note: only works on GitHub remotes currently*
|
37
|
+
|
38
|
+
Forms:
|
39
|
+
* `git pr` - Opens the comparison between upstream and origin for the current branch
|
40
|
+
* `git pr target_remote` - Opens the comparison between `target_remote` and origin for the current branch
|
41
|
+
* `git pr target_remote target_branch` - Opens the comparison between `target_remote` at the `target_branch` and origin at the current branch
|
42
|
+
* `git pr target_remote/target_branch source_remote/source_branch` - Opens the comparison between `target_remote` at the `target_branch` and `source_remote` at the `source_branch`
|
32
43
|
|
33
44
|
## Development
|
34
45
|
|
data/exe/git-pr
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'git/helpers'
|
3
|
+
require 'optparse'
|
4
|
+
|
5
|
+
OptionParser.new do |opts|
|
6
|
+
opts.banner = "Git-Helpers git pr\n"\
|
7
|
+
"Opens the default browser to a pull request creation window (only works for Github currently)\n"\
|
8
|
+
"Usages: git pr\n"\
|
9
|
+
" git pr target_remote\n"\
|
10
|
+
" git pr target_remote target_branch\n"\
|
11
|
+
' git pr target_remote/target_branch source_remote/source_branch'
|
12
|
+
opts.on_tail '-h', '--help', 'Shows this help message' do
|
13
|
+
puts opts
|
14
|
+
exit 0
|
15
|
+
end
|
16
|
+
opts.on_tail '-v', '--version', 'Shows the version of git-helpers' do
|
17
|
+
puts "Git-Helpers version #{Git::Helpers::VERSION}"
|
18
|
+
exit 0
|
19
|
+
end
|
20
|
+
end.parse!
|
21
|
+
|
22
|
+
target = ARGV.shift unless ARGV.empty?
|
23
|
+
source = ARGV.shift unless ARGV.empty?
|
24
|
+
|
25
|
+
if target.nil?
|
26
|
+
Git::Helpers.pull_request
|
27
|
+
else
|
28
|
+
target_remote, target_branch = Git::Helpers::Utils.split_remote_string(target)
|
29
|
+
if source.nil?
|
30
|
+
Git::Helpers.pull_request Dir.pwd, target_remote, target_branch
|
31
|
+
else
|
32
|
+
source_remote, source_branch = Git::Helpers::Utils.split_remote_string(source)
|
33
|
+
if target_branch.nil?
|
34
|
+
Git::Helpers.pull_request Dir.pwd, target_remote, source_remote
|
35
|
+
else
|
36
|
+
Git::Helpers.pull_request Dir.pwd, target_remote, target_branch, source_remote, source_branch
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,28 @@
|
|
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 an comparison page to open a pull request
|
9
|
+
# @param repo_dir [String] Directory of the git repo to browse, defaults to current working dir
|
10
|
+
# @param target_remote [String] Name of the target remote, default upstream
|
11
|
+
# @param target_branch [String] Name of the branch on the target remote to compare, defaults to current branch
|
12
|
+
# @param source_remote [String] Name of the source remote, default origin
|
13
|
+
# @param source_branch [String] Name of the branch on the source remote to compare, defaults to current branch
|
14
|
+
def self.pull_request(repo_dir = Dir.pwd, target = 'upstream', target_branch = nil, source = 'origin', source_branch = nil)
|
15
|
+
repo = Git.open(repo_dir)
|
16
|
+
raise "#{target} is not a known remote" unless Utils.remote? repo, target
|
17
|
+
raise "#{source} is not a known remote" unless Utils.remote? repo, source
|
18
|
+
target_remote = Utils.remotes_hash(repo)[target]
|
19
|
+
source_remote = Utils.remotes_hash(repo)[source]
|
20
|
+
target_branch ||= repo.current_branch
|
21
|
+
source_branch ||= repo.current_branch
|
22
|
+
url = target_remote.url.chomp('.git')
|
23
|
+
url = Utils.transform_url(url)
|
24
|
+
url << "/compare/#{target_branch}...#{Utils.true_name(source_remote)}:#{source_branch}?expand=1"
|
25
|
+
Launchy.open url
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/git/helpers/utils.rb
CHANGED
@@ -33,6 +33,26 @@ module Git
|
|
33
33
|
url
|
34
34
|
end
|
35
35
|
end
|
36
|
+
|
37
|
+
# Splits a remote/branch string into its component parts
|
38
|
+
# @param str [String] String to split
|
39
|
+
# @return [Array<String>] remote, branch
|
40
|
+
def self.split_remote_string(str)
|
41
|
+
first_slash = str.index('/')
|
42
|
+
if first_slash.nil?
|
43
|
+
return str, nil
|
44
|
+
else
|
45
|
+
return str[0..first_slash-1], str[first_slash+1..-1]
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# Gets the true name for a remote
|
50
|
+
# @param remote [Git::Remote] The remote to get the true name for
|
51
|
+
# @return [String] The true name of the remote, pulled from the url
|
52
|
+
def self.true_name(remote)
|
53
|
+
transform_url(remote.url) =~ %r{^https://.*?/(.*?)/.*$}
|
54
|
+
Regexp.last_match 1
|
55
|
+
end
|
36
56
|
end
|
37
57
|
end
|
38
58
|
end
|
data/lib/git/helpers/version.rb
CHANGED
data/lib/git/helpers.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: git-helpers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kierran McPherson
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-03-
|
11
|
+
date: 2016-03-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: launchy
|
@@ -157,6 +157,7 @@ email:
|
|
157
157
|
- kierranm@gmail.com
|
158
158
|
executables:
|
159
159
|
- git-browse
|
160
|
+
- git-pr
|
160
161
|
- git-update
|
161
162
|
extensions: []
|
162
163
|
extra_rdoc_files: []
|
@@ -170,10 +171,12 @@ files:
|
|
170
171
|
- README.md
|
171
172
|
- Rakefile
|
172
173
|
- exe/git-browse
|
174
|
+
- exe/git-pr
|
173
175
|
- exe/git-update
|
174
176
|
- git-helpers.gemspec
|
175
177
|
- lib/git/helpers.rb
|
176
178
|
- lib/git/helpers/browse.rb
|
179
|
+
- lib/git/helpers/pull_request.rb
|
177
180
|
- lib/git/helpers/update.rb
|
178
181
|
- lib/git/helpers/utils.rb
|
179
182
|
- lib/git/helpers/version.rb
|