git-friendly 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README +78 -0
- data/Rakefile +35 -0
- data/bin/git-follow +77 -0
- data/bin/git-publish +48 -0
- data/lib/git-friendly.rb +6 -0
- metadata +76 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Joshua Wehner
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
git-friendly
|
2
|
+
============
|
3
|
+
|
4
|
+
GitFriendly currently contains two commands that make working with remote branches easier in git.
|
5
|
+
|
6
|
+
|
7
|
+
git-publish
|
8
|
+
-----------
|
9
|
+
So, you've been working happily on feature_branch, and now you've come to the point where you'd like to
|
10
|
+
share your work with others. But you can never remember the series of arcane commands to coerce git into
|
11
|
+
publishing your branch to a remote. You try `git push`, but that doesn't do anything yet.
|
12
|
+
|
13
|
+
Enter git-publish.
|
14
|
+
|
15
|
+
Example:
|
16
|
+
$ git publish remote_name [branch_name]
|
17
|
+
|
18
|
+
remote_name is the name of the remote you'd like to publish to. You need to have configured this remote
|
19
|
+
already, configuring a new remote is beyond what git-publish is currently capable of doing
|
20
|
+
for you. Luckily, adding a new remote is not really that hard.
|
21
|
+
|
22
|
+
branch_name is optional. If you omit it, git-publish will assume you want to publish the currently
|
23
|
+
checked out branch. So, if you aren't working on the branch you'd like to publish, add
|
24
|
+
it here.
|
25
|
+
|
26
|
+
Here's what'll happen next:
|
27
|
+
$ git publish remote_name [branch_name]
|
28
|
+
>> Publish branch bug_fix/utf8_sphinx to jaw6 ? [Y/n]
|
29
|
+
|
30
|
+
If you hit enter, or y, or Y, or anything that isn't the letter n (n stands for "no"), then it'll go
|
31
|
+
ahead and do this:
|
32
|
+
|
33
|
+
git push #{remote_name} #{branch_name}:refs/heads/#{branch_name}"
|
34
|
+
git fetch #{remote_name}"
|
35
|
+
git config branch.#{branch_name}.remote #{remote_name}
|
36
|
+
git config branch.#{branch_name}.merge refs/heads/#{branch_name}"
|
37
|
+
|
38
|
+
From then on, you'll be able to push and pull as you'd expect.
|
39
|
+
|
40
|
+
git-follow
|
41
|
+
----------
|
42
|
+
So, someone just sent you an IM that says, "hey, I published that stuff on a branch, it's called
|
43
|
+
stuff_im_workin_on". You'd like to set up a tracking branch, but maybe you'd rather it be called
|
44
|
+
"new_feature_from_josh" locally. git-follow to the rescue!
|
45
|
+
|
46
|
+
Examples:
|
47
|
+
$ git follow remote_name/branch_name
|
48
|
+
$ git follow https://github.com/jaw6/reponame/tree/stuff_im_workin_on
|
49
|
+
$ git follow branch_name # will assume remote = 'origin'
|
50
|
+
|
51
|
+
Note that if you only provide a branch name, and it has slashes in it (like, "feature/branch_name"),
|
52
|
+
then git-follow will assume everything before the first slash is the remote_name (eg, "feature"). So, if
|
53
|
+
branch_name has slashes, you should probably explicity provide a remote_name. But don't worry if you
|
54
|
+
forget, because...
|
55
|
+
|
56
|
+
Here's what'll happen next:
|
57
|
+
>> What remote/branch should be tracked? [remote_name/branch_name]
|
58
|
+
>> What should it be called locally? [branch_name]
|
59
|
+
|
60
|
+
git-follow will show you the assumptions it's made, and allow you to override them. If you'd like the
|
61
|
+
branch to be called something else locally, you can tell it, and it'll do the right thing. If the
|
62
|
+
assumptions are correct, hit your enter key twice, and you'll be on your merry way.
|
63
|
+
|
64
|
+
And then this will happen in the background:
|
65
|
+
|
66
|
+
git fetch #{remote_name}
|
67
|
+
git branch --track #{local_branch_name} #{remote_name}/#{branch_name}
|
68
|
+
git checkout #{local_branch_name}
|
69
|
+
|
70
|
+
|
71
|
+
|
72
|
+
Do keep in mind
|
73
|
+
---------------
|
74
|
+
If you like working with remote branches so much, you should also check out Aanand Prasad's fantastic
|
75
|
+
git-up (https://github.com/aanand/git-up), which honestly has inspired quite a bit of what git-friendly
|
76
|
+
is trying to do.
|
77
|
+
|
78
|
+
Also: I might not actually know what I'm doing.
|
data/Rakefile
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
def gemspec
|
5
|
+
@gemspec ||= begin
|
6
|
+
file = File.expand_path('../git-friendly.gemspec', __FILE__)
|
7
|
+
eval(File.read(file), binding, file)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
begin
|
12
|
+
require 'rake/gempackagetask'
|
13
|
+
rescue LoadError
|
14
|
+
task(:gem) { $stderr.puts '`gem install rake` to package gems' }
|
15
|
+
else
|
16
|
+
Rake::GemPackageTask.new(gemspec) do |pkg|
|
17
|
+
pkg.gem_spec = gemspec
|
18
|
+
end
|
19
|
+
task :gem => :gemspec
|
20
|
+
end
|
21
|
+
|
22
|
+
desc "validate the gemspec"
|
23
|
+
task :gemspec do
|
24
|
+
gemspec.validate
|
25
|
+
end
|
26
|
+
|
27
|
+
require 'rake/rdoctask'
|
28
|
+
Rake::RDocTask.new do |rdoc|
|
29
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
30
|
+
|
31
|
+
rdoc.rdoc_dir = 'rdoc'
|
32
|
+
rdoc.title = "git-friendly #{version}"
|
33
|
+
rdoc.rdoc_files.include('README*')
|
34
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
35
|
+
end
|
data/bin/git-follow
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
#!/usr/local/bin/ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'colored' rescue nil
|
5
|
+
|
6
|
+
def colored?
|
7
|
+
String.new.respond_to?(:yellow)
|
8
|
+
end
|
9
|
+
|
10
|
+
abort("You didn't tell me which branch to follow!".send(colored? ? :red : 'to_s')) unless ARGV[0]
|
11
|
+
|
12
|
+
def remote_and_branch_from_github_url(string)
|
13
|
+
# example: https://github.com/jaw6/shopify/tree/bug_fix/utf8_sphinx -- .com/:remote_name/:repo/tree/:branch_name
|
14
|
+
if string =~ %r{\Ahttp[s]*://github\.com/([^/]+)/[^/]+/tree/(.+)\Z}
|
15
|
+
[$1, $2]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def remote_and_branch_from_input(string)
|
20
|
+
split_arg = string.split('/')
|
21
|
+
if split_arg.size == 1 # just one argument = that's a branch name, remote is 'origin'
|
22
|
+
remote_name, branch_name = 'origin', string
|
23
|
+
else
|
24
|
+
remote_name = split_arg.shift
|
25
|
+
branch_name = split_arg.join('/')
|
26
|
+
end
|
27
|
+
[remote_name, branch_name]
|
28
|
+
end
|
29
|
+
|
30
|
+
def question1(branch_name, remote_name, color=colored?)
|
31
|
+
msg = ''
|
32
|
+
if color
|
33
|
+
msg << '>> What remote/branch should be tracked? '.yellow
|
34
|
+
msg << " [#{remote_name}/#{branch_name}] ".white
|
35
|
+
else
|
36
|
+
msg = ">> What remote/branch should be tracked? [#{remote_name}/#{branch_name}] "
|
37
|
+
end
|
38
|
+
msg
|
39
|
+
end
|
40
|
+
|
41
|
+
def question2(branch_name, color=colored?)
|
42
|
+
msg = ''
|
43
|
+
if color
|
44
|
+
msg << '>> What should it be called locally? '.yellow
|
45
|
+
msg << " [#{branch_name}] ".white
|
46
|
+
else
|
47
|
+
msg = ">> What should it be called locally? [#{branch_name}] "
|
48
|
+
end
|
49
|
+
msg
|
50
|
+
end
|
51
|
+
|
52
|
+
def remote_and_branch(answer)
|
53
|
+
remote_and_branch_from_github_url(answer) || remote_and_branch_from_input(answer)
|
54
|
+
end
|
55
|
+
|
56
|
+
def get_remote_and_branch_from_user
|
57
|
+
remote_name, branch_name = remote_and_branch(ARGV[0])
|
58
|
+
print question1(branch_name, remote_name)
|
59
|
+
answer = STDIN.gets.strip
|
60
|
+
answer.empty? ? [remote_name, branch_name] : remote_and_branch(answer)
|
61
|
+
end
|
62
|
+
|
63
|
+
def get_local_branch_name_from_user(branch_name)
|
64
|
+
print question2(branch_name)
|
65
|
+
answer = STDIN.gets.strip
|
66
|
+
answer.empty? ? branch_name : answer
|
67
|
+
end
|
68
|
+
|
69
|
+
if (remote_name, branch_name = get_remote_and_branch_from_user) and local_branch_name = get_local_branch_name_from_user(branch_name)
|
70
|
+
commands = []
|
71
|
+
commands << fetch = "git fetch #{remote_name}"
|
72
|
+
commands << config_branch = "git branch --track #{local_branch_name} #{remote_name}/#{branch_name}"
|
73
|
+
commands << checkout = "git checkout #{local_branch_name}"
|
74
|
+
if `#{commands.join(' && ')}`
|
75
|
+
puts " ... success! Checked out #{local_branch_name} tracking #{remote_name}/#{branch_name}...".send(colored? ? :green : 'to_s')
|
76
|
+
end
|
77
|
+
end
|
data/bin/git-publish
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
#!/usr/local/bin/ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
colored = require 'colored' rescue nil
|
5
|
+
|
6
|
+
def load_grit_or_die!
|
7
|
+
require 'grit'
|
8
|
+
rescue
|
9
|
+
abort "Unable to load grit"
|
10
|
+
end
|
11
|
+
|
12
|
+
load_grit_or_die!
|
13
|
+
|
14
|
+
def get_branch_name
|
15
|
+
git_dir = `git rev-parse --git-dir`
|
16
|
+
repo = Grit::Repo.new(File.dirname(git_dir))
|
17
|
+
repo.head.name
|
18
|
+
rescue
|
19
|
+
abort "Cannot locate git repo"
|
20
|
+
end
|
21
|
+
|
22
|
+
remote_name = ARGV[0] || 'origin'
|
23
|
+
branch_name = ARGV[1] || get_branch_name
|
24
|
+
|
25
|
+
def question(branch_name, remote_name, color=false)
|
26
|
+
msg = ''
|
27
|
+
if color
|
28
|
+
msg << '>> Publish branch '.yellow
|
29
|
+
msg << branch_name.white
|
30
|
+
msg << ' to '.yellow
|
31
|
+
msg << remote_name.white
|
32
|
+
msg << ' ? [Y/n] '
|
33
|
+
else
|
34
|
+
msg = ">> Publish branch #{branch_name} to #{remote_name}? [Y/n] "
|
35
|
+
end
|
36
|
+
msg
|
37
|
+
end
|
38
|
+
|
39
|
+
print question(branch_name, remote_name, colored)
|
40
|
+
if STDIN.gets != "n\n"
|
41
|
+
commands = []
|
42
|
+
commands << push_to_remote = "git push #{remote_name} #{branch_name}:refs/heads/#{branch_name}"
|
43
|
+
commands << fetch = "git fetch #{remote_name}"
|
44
|
+
commands << config_branch = "git config branch.#{branch_name}.remote #{remote_name} && git config branch.#{branch_name}.merge refs/heads/#{branch_name}"
|
45
|
+
if `#{commands.join(' && ')}`
|
46
|
+
puts " ... success! Published to #{remote_name}:#{branch_name}...".send(colored ? :green : 'to_s')
|
47
|
+
end
|
48
|
+
end
|
data/lib/git-friendly.rb
ADDED
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: git-friendly
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- joshua wehner
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-10-05 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: colored
|
16
|
+
requirement: &2157432420 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.2'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *2157432420
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: grit
|
27
|
+
requirement: &2157431360 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *2157431360
|
36
|
+
description: GitFriendly currently contains two commands that make working with remote
|
37
|
+
branches easier in git.
|
38
|
+
email:
|
39
|
+
- joshua.wehner@gmail.com
|
40
|
+
executables:
|
41
|
+
- git-follow
|
42
|
+
- git-publish
|
43
|
+
extensions: []
|
44
|
+
extra_rdoc_files: []
|
45
|
+
files:
|
46
|
+
- bin/git-follow
|
47
|
+
- bin/git-publish
|
48
|
+
- lib/git-friendly.rb
|
49
|
+
- LICENSE
|
50
|
+
- README
|
51
|
+
- Rakefile
|
52
|
+
homepage: http://github.com/jaw6/git-friendly
|
53
|
+
licenses: []
|
54
|
+
post_install_message:
|
55
|
+
rdoc_options: []
|
56
|
+
require_paths:
|
57
|
+
- lib
|
58
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
60
|
+
requirements:
|
61
|
+
- - ! '>='
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
requirements: []
|
71
|
+
rubyforge_project:
|
72
|
+
rubygems_version: 1.8.7
|
73
|
+
signing_key:
|
74
|
+
specification_version: 3
|
75
|
+
summary: git commands to make tracking and publishing remote branches easier for everyone
|
76
|
+
test_files: []
|