grb 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. data/README.rdoc +7 -3
  2. data/TODO +0 -1
  3. data/VERSION +1 -1
  4. data/bin/grb +2 -4
  5. data/lib/grb.rb +125 -0
  6. metadata +6 -5
data/README.rdoc CHANGED
@@ -1,14 +1,18 @@
1
1
  = GRB
2
- re-implement git_remote_branch [http://github.com/webmat/git_remote_branch] for cleaner,simpler,stronger!
2
+ A tool to simplify working with remote branches.
3
3
 
4
4
  == Install:
5
- $ sudo gem install jinzhu-grb
5
+ $ sudo gem install grb
6
6
 
7
7
  == USAGE:
8
8
  * rename `branch1` to `branch2`
9
9
  $ grb mv [branch1] [branch2] [--explain]
10
10
  * rename current branch to `branch`
11
11
  $ grb mv branch [--explain]
12
+ * add a remote repo
13
+ $ grb remote_add `name` `repo path` [--explain]
14
+ * remove a remote repo
15
+ $ grb remote_rm `name` [--explain]
12
16
  * delete branch `branch`,default current_branch
13
17
  $ grb rm [branch] [--explain]
14
18
  * pull branch `branch`,default current_branch
@@ -18,7 +22,7 @@
18
22
  * create new branch `branch`
19
23
  $ grb new [branch] [--explain]
20
24
 
21
- Copyright (c) 2009-present GPL3
25
+ Copyright (c) 2009-present MIT
22
26
 
23
27
  Author : Jinzhu Zhang
24
28
  Email : wosmvp@gmail.com
data/TODO CHANGED
@@ -11,4 +11,3 @@ grb
11
11
  pull fetch
12
12
 
13
13
  push publish
14
-
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.1
1
+ 0.4.0
data/bin/grb CHANGED
@@ -1,10 +1,9 @@
1
1
  #!/usr/bin/env ruby
2
2
  #
3
- # Copyright (c) 2009-present. GPL3.
3
+ # Copyright (c) 2009-present. MIT.
4
4
  # Author: Zhang Jinzhu
5
5
 
6
- $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/../lib"))
7
- require "grb"
6
+ require File.expand_path(File.dirname(__FILE__) + "/../lib/grb")
8
7
 
9
8
  # easy debugger
10
9
  if ARGV.delete('--debug')
@@ -13,7 +12,6 @@ else
13
12
  def debugger;end
14
13
  end
15
14
 
16
-
17
15
  abort('Version: ' + File.read(File.expand_path("../../VERSION",__FILE__))) if ARGV.delete('--version') || ARGV.delete('-v')
18
16
 
19
17
  EXPLAIN = ARGV.delete('--explain') || ARGV.delete('-e')
data/lib/grb.rb ADDED
@@ -0,0 +1,125 @@
1
+ class Grb
2
+ GIT = ENV['GRB_GIT'] || 'git'
3
+ ORIGIN = ENV['GRB_ORIGIN'] || 'origin'
4
+
5
+ COMMANDS = {
6
+ :new => {
7
+ :desc => "=> create new branch `branch`\ngrb new [branch] [--explain]",
8
+ :commands => [
9
+ '"#{GIT} push #{origin} #{current_branch}:refs/heads/#{branch}"',
10
+ '"#{GIT} fetch #{origin}"',
11
+ '"#{GIT} branch --track #{branch} #{origin}/#{branch}"',
12
+ '"#{GIT} checkout #{branch}"'
13
+ ]
14
+ },
15
+
16
+ :push => {
17
+ :desc => "=> push branch `branch`, default current_branch\ngrb push [branch] [--explain]",
18
+ :commands => [
19
+ '"#{GIT} push #{origin} #{branch}:refs/heads/#{branch}"',
20
+ '"#{GIT} fetch #{origin}"',
21
+ '"#{GIT} config branch.#{branch}.remote #{origin}"',
22
+ '"#{GIT} config branch.#{branch}.merge refs/heads/#{branch}"',
23
+ '"#{GIT} checkout #{branch}"'
24
+ ]
25
+ },
26
+
27
+ :mv => {
28
+ :desc => "=> rename `branch1` to `branch2`\ngrb mv [branch1] [branch2] [--explain]\n=> rename current branch to `branch`\ngrb mv branch [--explain]",
29
+ :commands => [
30
+ ' if(branch != branch_)
31
+ "#{GIT} push #{origin} #{branch}:refs/heads/#{branch_}
32
+ #{GIT} fetch #{origin}
33
+ #{GIT} branch --track #{branch_} #{origin}/#{branch_}
34
+ #{GIT} checkout #{branch_}
35
+ #{GIT} branch -d #{branch}
36
+ #{GIT} push #{origin} :refs/heads/#{branch}"
37
+ else
38
+ "#{GIT} push #{origin} #{current_branch}:refs/heads/#{branch}
39
+ #{GIT} fetch #{origin}
40
+ #{GIT} branch --track #{branch} #{origin}/#{branch}
41
+ #{GIT} checkout #{branch}
42
+ #{GIT} push #{origin} :refs/heads/#{current_branch}
43
+ #{GIT} branch -d #{current_branch}"
44
+ end'
45
+ ]
46
+ },
47
+
48
+ :rm => {
49
+ :desc => "=> delete branch `branch`,default current_branch\ngrb rm [branch] [--explain]",
50
+ :commands => [
51
+ '"#{GIT} push #{origin} :refs/heads/#{branch}"',
52
+ '"#{GIT} checkout master" if current_branch == branch',
53
+ '"#{GIT} branch -d #{branch}"'
54
+ ]
55
+ },
56
+
57
+ :pull => {
58
+ :desc => "=> pull branch `branch`,default current_branch\ngrb pull [branch] [--explain]",
59
+ :commands => [
60
+ '"#{GIT} fetch #{origin}"',
61
+ 'if local_branches.include?(branch)
62
+ "#{GIT} config branch.#{branch}.remote #{origin}\n" +
63
+ "#{GIT} config branch.#{branch}.merge refs/heads/#{branch}"
64
+ else
65
+ "#{GIT} branch --track #{branch} #{origin}/#{branch}"
66
+ end',
67
+ '"#{GIT} checkout #{branch}" if current_branch != branch',
68
+ '"#{GIT} rebase #{origin}/#{branch}"',
69
+ ]
70
+ },
71
+
72
+ :track => {
73
+ :desc => "=> track branch\ngrb track `branch` [--explain]",
74
+ :commands => [
75
+ '"#{GIT} fetch #{origin}"',
76
+ '"#{GIT} branch --track #{branch} origin/#{branch}"',
77
+ '"#{GIT} checkout #{branch}"'
78
+ ]
79
+ },
80
+
81
+ :remote_add => {
82
+ :desc => "=> add a remote repo\ngrb remote_add `name` `repo path` [--explain]",
83
+ :commands => [
84
+ '"#{GIT} remote add #{branch} #{branch_}"',
85
+ '"#{GIT} fetch #{branch}"'
86
+ ]
87
+ },
88
+
89
+ :remote_rm => {
90
+ :desc => "=> remove a remote repo\ngrb remote_rm `name` [--explain]",
91
+ :commands => [
92
+ '"#{GIT} remote rm #{branch}"',
93
+ ]
94
+ }
95
+ }
96
+
97
+ def self.parse(opt)
98
+ if COMMANDS.keys.include?(opt[:command].to_sym)
99
+ current_branch,branch,branch_,origin = get_current_branch,opt[:branch],opt[:branch_],ORIGIN
100
+
101
+ COMMANDS[opt[:command].to_sym][:commands].map {|x| exec_cmd(eval(x))}
102
+ else
103
+ help
104
+ end
105
+ end
106
+
107
+ def self.exec_cmd(str)
108
+ return true unless str
109
+ puts("\e[031m" + str.gsub(/^\s*/,'') + "\e[0m")
110
+ system("#{str}") unless EXPLAIN
111
+ end
112
+
113
+ def self.get_current_branch
114
+ (`#{GIT} branch 2> /dev/null | grep '^\*'`).gsub(/[\*\s]/,'')
115
+ end
116
+
117
+ def self.local_branches
118
+ (`#{GIT} branch -l`).split(/\n/).map{|x| x.gsub(/[\*\s]/,'')}
119
+ end
120
+
121
+ def self.help(*args)
122
+ puts "USAGE:"
123
+ COMMANDS.values.map {|x| puts x[:desc].gsub(/^(\W.*)$/,"\e[31m" + '\1' + "\e[0m").gsub(/^(\w.*)$/,' $ \1')}
124
+ end
125
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grb
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 15
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 3
9
- - 1
10
- version: 0.3.1
8
+ - 4
9
+ - 0
10
+ version: 0.4.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jinzhu Zhang
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-07-19 00:00:00 +08:00
18
+ date: 2010-07-20 00:00:00 +08:00
19
19
  default_executable: grb
20
20
  dependencies: []
21
21
 
@@ -30,6 +30,7 @@ extra_rdoc_files:
30
30
  - TODO
31
31
  files:
32
32
  - VERSION
33
+ - lib/grb.rb
33
34
  - README.rdoc
34
35
  - TODO
35
36
  - bin/grb