git-pcheckout 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/Guardfile +10 -0
- data/LICENSE.txt +22 -0
- data/README.md +44 -0
- data/Rakefile +1 -0
- data/bin/git-pcheckout +21 -0
- data/git-pcheckout.gemspec +24 -0
- data/git-pcheckout.rb +71 -0
- data/lib/git-pcheckout/version.rb +3 -0
- data/lib/handle-branch.rb +43 -0
- data/spec/git-pcheckout_spec.rb +60 -0
- data/spec/lib/handle-branch_spec.rb +40 -0
- data/tmp/.keep +0 -0
- metadata +105 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
NjU5NjEzMGNiMzAyODk2ZTFlMzk4Y2E1ZDk1OGI2NGM2OGZiYjFhYg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MTA3NGUyNzg1YWQ5YjcxMmI5OTkyZWE2M2EzNGM2MWUyODc0NGQ1OA==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
Mjg0NTJjMjNmZGY5NGI4Zjc4YmJjODk1MWRhZGY4MWViMzE0OGI0NGFiNTdk
|
10
|
+
ZmE4Nzk2YzBlNDJlMDVjODM3Yjk2NDE2ODYzMmUzNmFhYWE1ZmQzNDU4N2Nl
|
11
|
+
NjY3MmM5NTQwNmU1OTc4MmQwMzgxZmIzNzVjNDk2MTU3OTc4ZmY=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MzcyMTZkZDdmNmMyNmVhNGJkODFhNDk1YTNkMWE5MWMwOWU5ZDIzMzc3N2E2
|
14
|
+
NzBmOTQ1NjFhZWQwNDMwNmQ5OWZjYWYzMmIwODNhZGE4ODBkN2QyZTUyNzMw
|
15
|
+
YTI0Y2NmYjYxNTRhNzk5MTBlYTUyNzM0MDEwODI4YTE5ZTY3YTU=
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
guard :rspec do
|
5
|
+
watch(%r{^spec/.+_spec\.rb$})
|
6
|
+
watch(%r{^(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
7
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
8
|
+
watch('spec/spec_helper.rb') { "spec" }
|
9
|
+
end
|
10
|
+
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Vladimir Rybas
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# git-pcheckout
|
2
|
+
|
3
|
+
Git command to evenly checkout local/remote branches and source/forks
|
4
|
+
pull pequests by URL (with Hub)
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
[Hub][1] is required for checking out pull requests.
|
9
|
+
|
10
|
+
$ brew install hub
|
11
|
+
$ gem install git-pcheckout
|
12
|
+
|
13
|
+
## Usage
|
14
|
+
|
15
|
+
$ git pcheckout 123-myfeature
|
16
|
+
$ git pcheckout https://github.com/user/repo/pull/123
|
17
|
+
|
18
|
+
## What it does
|
19
|
+
|
20
|
+
If specified _branch-name_ exists locally:
|
21
|
+
|
22
|
+
$ git checkout branch-name
|
23
|
+
$ git pull origin branch-name
|
24
|
+
|
25
|
+
If specified _branch-name_ not exist locally:
|
26
|
+
|
27
|
+
$ git fetch
|
28
|
+
$ git checkout --track origin/branch-name
|
29
|
+
|
30
|
+
If pull request URL specified(from fork):
|
31
|
+
- pulls fork branch with Hub
|
32
|
+
|
33
|
+
If pull request URL specified(from source repo):
|
34
|
+
- treats it as if just a _branch_name_ was specified (goto 1)
|
35
|
+
|
36
|
+
## Contributing
|
37
|
+
|
38
|
+
1. Fork it ( http://github.com/vrybas/git-pcheckout/fork )
|
39
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
40
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
41
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
42
|
+
5. Create new Pull Request
|
43
|
+
|
44
|
+
[1]: http://hub.github.com/
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/git-pcheckout
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# Usage: git pcheckout [<branch-name>]
|
4
|
+
#
|
5
|
+
# If local <branch-name> exists:
|
6
|
+
# - git checkout <branch-name>
|
7
|
+
# - git pull origin <branch-name>
|
8
|
+
|
9
|
+
# If local <branch-name> not exist:
|
10
|
+
# - git fetch
|
11
|
+
# - git checkout --track origin/<branch-name>
|
12
|
+
#
|
13
|
+
# If pull request URL specified(from fork):
|
14
|
+
# - pulls fork branch with Hub
|
15
|
+
#
|
16
|
+
# If pull request URL specified(from source repo):
|
17
|
+
# - treats it as if just a branch name was specified (goto 1)
|
18
|
+
|
19
|
+
require_relative '../git-pcheckout.rb'
|
20
|
+
|
21
|
+
GitPcheckout.(ARGV[0])
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'git-pcheckout/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "git-pcheckout"
|
8
|
+
spec.version = GitPcheckout::VERSION
|
9
|
+
spec.authors = ["Vladimir Rybas"]
|
10
|
+
spec.email = ["vladimirrybas@gmail.com"]
|
11
|
+
spec.summary = %q{Git command to evenly checkout local/remote branches and source/forks pull pequests by URL (with Hub)}
|
12
|
+
spec.description = %q{Git command to evenly checkout local/remote branches and source/forks pull pequests by URL (with Hub)}
|
13
|
+
spec.homepage = "https://github.com/vrybas/git-pcheckout"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
end
|
data/git-pcheckout.rb
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
require_relative 'lib/handle-branch.rb'
|
2
|
+
|
3
|
+
class GitPcheckout < Struct.new(:arg)
|
4
|
+
|
5
|
+
def self.call(*args)
|
6
|
+
new(*args).call
|
7
|
+
end
|
8
|
+
|
9
|
+
def initialize(arg)
|
10
|
+
self.arg = arg
|
11
|
+
end
|
12
|
+
|
13
|
+
def call
|
14
|
+
if pull_request_url?(arg)
|
15
|
+
handle_pull_request_url(arg)
|
16
|
+
else
|
17
|
+
handle_branch_name(arg)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def pull_request_url?(arg)
|
24
|
+
arg.match /https:\/\/github.com\//
|
25
|
+
end
|
26
|
+
|
27
|
+
def handle_pull_request_url(url)
|
28
|
+
puts "handling Pull Request URL..."
|
29
|
+
|
30
|
+
branch_name_with_prefix = checkout_pull_request_branch(url)
|
31
|
+
|
32
|
+
if source_repository_branch?(branch_name_with_prefix)
|
33
|
+
handle_source_branch(branch_name_with_prefix)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def checkout_pull_request_branch(url)
|
38
|
+
out = `hub checkout #{url}`
|
39
|
+
return false if out == ''
|
40
|
+
out.scan(/Branch (.+) set/).flatten.first
|
41
|
+
end
|
42
|
+
|
43
|
+
def source_repository_branch?(branch_name)
|
44
|
+
branch_name.start_with?("#{origin_user_name}-")
|
45
|
+
end
|
46
|
+
|
47
|
+
def substitute_prefix(branch_name)
|
48
|
+
branch_name.gsub("#{origin_user_name}-",'')
|
49
|
+
end
|
50
|
+
|
51
|
+
def origin_user_name
|
52
|
+
origin_url.scan(/([\w\-_]+)\/[\w\-_]+.git/).flatten[0]
|
53
|
+
end
|
54
|
+
|
55
|
+
def origin_url
|
56
|
+
`git config --get remote.origin.url`
|
57
|
+
end
|
58
|
+
|
59
|
+
def handle_source_branch(branch_name_with_prefix)
|
60
|
+
handle_branch_name(substitute_prefix(branch_name_with_prefix)) &&
|
61
|
+
delete_branch(branch_name_with_prefix)
|
62
|
+
end
|
63
|
+
|
64
|
+
def delete_branch(branch_name)
|
65
|
+
system("git branch -D #{branch_name}")
|
66
|
+
end
|
67
|
+
|
68
|
+
def handle_branch_name(branch)
|
69
|
+
HandleBranch.(branch)
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
class HandleBranch < Struct.new(:branch)
|
2
|
+
|
3
|
+
def self.call(*args)
|
4
|
+
new(*args).call
|
5
|
+
end
|
6
|
+
|
7
|
+
def initialize(branch)
|
8
|
+
self.branch = branch
|
9
|
+
end
|
10
|
+
|
11
|
+
def call
|
12
|
+
if branch_exists_locally?
|
13
|
+
checkout_local_branch && pull_from_origin
|
14
|
+
else
|
15
|
+
fetch_from_origin && checkout_and_track_branch
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
def branch_exists_locally?
|
21
|
+
return true unless `git show-ref refs/heads/#{branch}`.empty?
|
22
|
+
end
|
23
|
+
|
24
|
+
def checkout_local_branch
|
25
|
+
puts "branch already exists. Checkout..."
|
26
|
+
system "git checkout #{branch}"
|
27
|
+
end
|
28
|
+
|
29
|
+
def pull_from_origin
|
30
|
+
puts "pull from origin..."
|
31
|
+
system "git pull origin #{branch}"
|
32
|
+
end
|
33
|
+
|
34
|
+
def fetch_from_origin
|
35
|
+
puts "no local branch found. Fetching from origin..."
|
36
|
+
system "git fetch origin"
|
37
|
+
end
|
38
|
+
|
39
|
+
def checkout_and_track_branch
|
40
|
+
puts "checkout and track branch..."
|
41
|
+
system "git checkout --track origin/#{branch}"
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require_relative '../git-pcheckout.rb'
|
2
|
+
|
3
|
+
describe GitPcheckout do
|
4
|
+
|
5
|
+
context ".call" do
|
6
|
+
it "should delegate to #new() with all params" do
|
7
|
+
expect_any_instance_of(described_class).to receive("call").and_return(true)
|
8
|
+
instance = described_class.("foo")
|
9
|
+
expect(instance).to be
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should send #call() to created instance" do
|
13
|
+
expect_any_instance_of(described_class).to receive("call")
|
14
|
+
described_class.("foo")
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context "#initialize" do
|
19
|
+
it "should set @arg" do
|
20
|
+
instance = described_class.new("foo")
|
21
|
+
expect(instance.arg).to eql("foo")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context "#call" do
|
26
|
+
context "plain branch name" do
|
27
|
+
it "should handle plain branch name" do
|
28
|
+
expect_any_instance_of(described_class).to receive("pull_request_url?").and_return(false)
|
29
|
+
expect_any_instance_of(HandleBranch).to receive("call").and_return(true)
|
30
|
+
described_class.("foo")
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context "pull request url" do
|
35
|
+
it "should handle pull_request_url" do
|
36
|
+
expect_any_instance_of(described_class).to receive("handle_pull_request_url").and_return(true)
|
37
|
+
described_class.("https://github.com/user/repo.git")
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should pull branch with prefix" do
|
41
|
+
origin_url = "git@github.com/user/repo-name.git"
|
42
|
+
url = "https://github.com/forked-user/repo-name/pull/18"
|
43
|
+
expect_any_instance_of(described_class).to receive("origin_url").and_return(origin_url)
|
44
|
+
expect_any_instance_of(described_class).to receive("checkout_pull_request_branch").and_return("forked-user-branch_name")
|
45
|
+
described_class.(url)
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should handle a source branch, specified in pull request" do
|
49
|
+
origin_url = "git@github.com/user/repo-name.git"
|
50
|
+
url = "https://github.com/user/repo-name/pull/18"
|
51
|
+
expect_any_instance_of(described_class).to receive("origin_url").twice.and_return(origin_url)
|
52
|
+
expect_any_instance_of(described_class).to receive("checkout_pull_request_branch").and_return("user-branch_name")
|
53
|
+
expect(HandleBranch).to receive("call").with("branch_name").and_return(true)
|
54
|
+
expect_any_instance_of(described_class).to receive("delete_branch").and_return(true)
|
55
|
+
described_class.(url)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require_relative '../../lib/handle-branch.rb'
|
2
|
+
|
3
|
+
describe HandleBranch do
|
4
|
+
|
5
|
+
context ".call" do
|
6
|
+
it "should delegate to #new() with all params" do
|
7
|
+
expect_any_instance_of(HandleBranch).to receive("call").and_return(true)
|
8
|
+
instance = HandleBranch.("foo")
|
9
|
+
expect(instance).to be
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should send #call() to created instance" do
|
13
|
+
expect_any_instance_of(HandleBranch).to receive("call")
|
14
|
+
HandleBranch.("foo")
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context "#initialize" do
|
19
|
+
it "should set @branch" do
|
20
|
+
instance = HandleBranch.new("foo")
|
21
|
+
expect(instance.branch).to eql("foo")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context "#call" do
|
26
|
+
it "should checkout and pull if branch exists" do
|
27
|
+
expect_any_instance_of(HandleBranch).to receive("branch_exists_locally?").and_return(true)
|
28
|
+
expect_any_instance_of(HandleBranch).to receive("checkout_local_branch").and_return(true)
|
29
|
+
expect_any_instance_of(HandleBranch).to receive("pull_from_origin").and_return(true)
|
30
|
+
HandleBranch.("foo")
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should fetch and checkout with track if branch not exist" do
|
34
|
+
expect_any_instance_of(HandleBranch).to receive("branch_exists_locally?").and_return(false)
|
35
|
+
expect_any_instance_of(HandleBranch).to receive("fetch_from_origin").and_return(true)
|
36
|
+
expect_any_instance_of(HandleBranch).to receive("checkout_and_track_branch").and_return(true)
|
37
|
+
HandleBranch.("foo")
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/tmp/.keep
ADDED
File without changes
|
metadata
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: git-pcheckout
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Vladimir Rybas
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-03-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Git command to evenly checkout local/remote branches and source/forks
|
56
|
+
pull pequests by URL (with Hub)
|
57
|
+
email:
|
58
|
+
- vladimirrybas@gmail.com
|
59
|
+
executables:
|
60
|
+
- git-pcheckout
|
61
|
+
extensions: []
|
62
|
+
extra_rdoc_files: []
|
63
|
+
files:
|
64
|
+
- .gitignore
|
65
|
+
- Gemfile
|
66
|
+
- Guardfile
|
67
|
+
- LICENSE.txt
|
68
|
+
- README.md
|
69
|
+
- Rakefile
|
70
|
+
- bin/git-pcheckout
|
71
|
+
- git-pcheckout.gemspec
|
72
|
+
- git-pcheckout.rb
|
73
|
+
- lib/git-pcheckout/version.rb
|
74
|
+
- lib/handle-branch.rb
|
75
|
+
- spec/git-pcheckout_spec.rb
|
76
|
+
- spec/lib/handle-branch_spec.rb
|
77
|
+
- tmp/.keep
|
78
|
+
homepage: https://github.com/vrybas/git-pcheckout
|
79
|
+
licenses:
|
80
|
+
- MIT
|
81
|
+
metadata: {}
|
82
|
+
post_install_message:
|
83
|
+
rdoc_options: []
|
84
|
+
require_paths:
|
85
|
+
- lib
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ! '>='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ! '>='
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
requirements: []
|
97
|
+
rubyforge_project:
|
98
|
+
rubygems_version: 2.2.2
|
99
|
+
signing_key:
|
100
|
+
specification_version: 4
|
101
|
+
summary: Git command to evenly checkout local/remote branches and source/forks pull
|
102
|
+
pequests by URL (with Hub)
|
103
|
+
test_files:
|
104
|
+
- spec/git-pcheckout_spec.rb
|
105
|
+
- spec/lib/handle-branch_spec.rb
|