misaka-braid 0.4.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt ADDED
@@ -0,0 +1,4 @@
1
+ == 0.1.0 2007-08-23
2
+
3
+ * 1 major enhancement:
4
+ * Initial release
data/License.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2007 Cristi Balan
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/Manifest.txt ADDED
@@ -0,0 +1,32 @@
1
+ History.txt
2
+ License.txt
3
+ Manifest.txt
4
+ README.txt
5
+ Rakefile
6
+ bin/braid
7
+ config/hoe.rb
8
+ config/requirements.rb
9
+ lib/braid.rb
10
+ lib/braid/command.rb
11
+ lib/braid/commands/add.rb
12
+ lib/braid/commands/diff.rb
13
+ lib/braid/commands/remove.rb
14
+ lib/braid/commands/setup.rb
15
+ lib/braid/commands/update.rb
16
+ lib/braid/config.rb
17
+ lib/braid/exceptions.rb
18
+ lib/braid/operations.rb
19
+ lib/braid/version.rb
20
+ braid.gemspec
21
+ script/destroy
22
+ script/generate
23
+ setup.rb
24
+ spec/braid_spec.rb
25
+ spec/config_spec.rb
26
+ spec/operations_spec.rb
27
+ spec/spec.opts
28
+ spec/spec_helper.rb
29
+ tasks/deployment.rake
30
+ tasks/environment.rake
31
+ tasks/rspec.rake
32
+ tasks/website.rake
data/README.txt ADDED
@@ -0,0 +1,53 @@
1
+ = Braid
2
+
3
+ http://evil.che.lu/projects/braid/
4
+
5
+ == Description
6
+
7
+ Braid is a simple tool to help track git and svn vendor branches in a git
8
+ repository.
9
+
10
+ In purpose, it's similar to piston, but it's especially built on top of git
11
+ commands. This allows better integration with git and easier management of
12
+ merges.
13
+
14
+ Braid is "hosted on github":http://github.com/evilchelu/braid.
15
+
16
+ *NOTE:* You will need at least git 1.5.4.5+ to run braid. You'll also need the
17
+ open4 and main gems.
18
+
19
+ == Install with rubygems
20
+
21
+ gem sources -a http://gems.github.com/ # only need to do this once
22
+ gem install evilchelu-braid
23
+
24
+ == Install from the git repository
25
+
26
+ Get a clone of the git repository using:
27
+
28
+ git clone git://github.com/evilchelu/braid.git
29
+ cd braid
30
+ rake install_gem
31
+ braid --help # see usage
32
+
33
+ === Usage
34
+
35
+ braid help
36
+ braid help COMMANDNAME
37
+
38
+ For more usage examples, documentation, feature requests and bug reporting,
39
+ check out the "braid wiki":http://github.com/evilchelu/braid/wikis.
40
+
41
+ === Contributing
42
+
43
+ If you want to send a patch in, please fork the project on github, commit your
44
+ changes and send a pull request.
45
+
46
+ === Mad props
47
+
48
+ Braid used to be quite lame before "Norbert Crombach":http://primetheory.org/
49
+ ("github":http://github.com/norbert) resuscitated it by contribuing a bunch of
50
+ code.
51
+
52
+ He rocks! Go buy him a beer.
53
+
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ require 'config/requirements'
2
+ require 'config/hoe' # setup Hoe + all gem configuration
3
+
4
+ Dir['tasks/**/*.rake'].each { |rake| load rake }
data/bin/braid ADDED
@@ -0,0 +1,218 @@
1
+ #!/usr/bin/env ruby
2
+ $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/../lib"))
3
+
4
+ begin
5
+ require 'rubygems'
6
+ rescue LoadError
7
+ end
8
+ require 'main'
9
+
10
+ require 'braid'
11
+
12
+ Home = File.expand_path(ENV['HOME'] || '~')
13
+
14
+ # mostly blantantly stolen from ara's punch script
15
+ # main kicks ass!
16
+ Main {
17
+ description <<-TXT
18
+ braid is a simple tool to help track git or svn repositories inside a git repository.
19
+
20
+ Run 'braid help commandname' for more details.
21
+
22
+ All operations will be executed in the braid/track branch.
23
+ You can then merge back or cherry-pick changes.
24
+ TXT
25
+
26
+ mode(:add) {
27
+ description <<-TXT
28
+ Add a new mirror to be tracked.
29
+
30
+ * adds metadata about the mirror to .braids
31
+ * adds the git or git svn remotes to .git/config
32
+ * fetches and merges remote code into given directory
33
+
34
+ --type defaults:
35
+
36
+ * svn://path # => svn
37
+ * git://path # => git
38
+ * http://path/trunk # => svn
39
+ * http://path.git # => git
40
+
41
+ Name defaults:
42
+
43
+ * remote/path # => path
44
+ * remote/path/trunk # => path
45
+ * remote/path.git # => path
46
+ TXT
47
+
48
+ examples <<-TXT
49
+ . braid add svn://remote/path
50
+ . braid add svn://remote/path local/dir
51
+ . braid add git://remote/path local/dir
52
+ . braid add http://remote/path.git local/dir
53
+ . braid add http://remote/path --type git local/dir
54
+ . braid add svn://remote/path --branch notmaster
55
+ TXT
56
+
57
+ mixin :argument_remote, :option_type, :optional_mirror, :option_branch, :option_rails_plugin, :option_revision, :option_full
58
+
59
+ run {
60
+ Braid::Command.run(:add, remote, { "type" => type, "mirror" => mirror, "branch" => branch, "rails_plugin" => rails_plugin, "revision" => revision, "full" => full })
61
+ }
62
+ }
63
+
64
+ mode(:update) {
65
+ description <<-TXT
66
+ Update a braid mirror.
67
+
68
+ * get new changes from remote
69
+ * always creates a merge commit
70
+ * updates metadata in .braids when revisions are changed
71
+
72
+ Defaults to updating all unlocked mirrors if none is specified.
73
+ TXT
74
+
75
+ examples <<-TXT
76
+ . braid update
77
+ . braid update local/dir
78
+ TXT
79
+
80
+ mixin :optional_mirror, :option_revision, :option_head
81
+
82
+ run {
83
+ Braid::Command.run(:update, mirror, { "revision" => revision, "head" => head })
84
+ }
85
+ }
86
+
87
+ mode(:remove) {
88
+ description <<-TXT
89
+ Remove a mirror.
90
+
91
+ * removes metadata from .braids
92
+ * removes the local directory and commits the removal
93
+ * does NOT remove the git and git svn remotes in case you still need them around
94
+ TXT
95
+
96
+ examples <<-TXT
97
+ . braid remove local/dir
98
+ TXT
99
+
100
+ mixin :argument_mirror
101
+
102
+ run {
103
+ Braid::Command.run(:remove, mirror)
104
+ }
105
+ }
106
+
107
+ mode(:setup) {
108
+ description <<-TXT
109
+ Set up git and git-svn remotes.
110
+ TXT
111
+
112
+ examples <<-TXT
113
+ . braid setup local/dir
114
+ TXT
115
+
116
+ mixin :optional_mirror
117
+
118
+ run {
119
+ Braid::Command.run(:setup, mirror)
120
+ }
121
+ }
122
+
123
+ mode(:diff) {
124
+ description <<-TXT
125
+ Show diff between '#{Braid::WORK_BRANCH}' and HEAD.
126
+ TXT
127
+
128
+ examples <<-TXT
129
+ . braid diff local/dir
130
+ TXT
131
+
132
+ mixin :argument_mirror
133
+
134
+ run {
135
+ Braid::Command.run(:diff, mirror)
136
+ }
137
+ }
138
+
139
+ mode(:version) {
140
+ description 'Show braid version.'
141
+
142
+ run {
143
+ puts "braid #{Braid::VERSION::STRING}"
144
+ }
145
+ }
146
+
147
+ mixin(:argument_mirror) {
148
+ argument(:mirror) {
149
+ attr
150
+ }
151
+ }
152
+
153
+ mixin(:optional_mirror) {
154
+ argument(:mirror) {
155
+ optional
156
+ attr
157
+ }
158
+ }
159
+
160
+ mixin(:argument_remote) {
161
+ argument(:remote) {
162
+ attr
163
+ }
164
+ }
165
+
166
+ mixin(:option_type) {
167
+ option(:type, :t) {
168
+ optional
169
+ argument :required
170
+ desc 'mirror type'
171
+ attr
172
+ }
173
+ }
174
+
175
+ mixin(:option_branch) {
176
+ option(:branch, :b) {
177
+ optional
178
+ argument :required
179
+ desc 'remote branch name'
180
+ attr
181
+ }
182
+ }
183
+
184
+ mixin(:option_rails_plugin) {
185
+ option(:rails_plugin, :p) {
186
+ optional
187
+ desc 'added mirror is a Rails plugin'
188
+ attr
189
+ }
190
+ }
191
+
192
+ mixin(:option_revision) {
193
+ option(:revision, :r) {
194
+ optional
195
+ argument :required
196
+ desc 'revision to track'
197
+ attr
198
+ }
199
+ }
200
+
201
+ mixin(:option_head) {
202
+ option(:head) {
203
+ optional
204
+ desc 'mirror head'
205
+ attr
206
+ }
207
+ }
208
+
209
+ mixin(:option_full) {
210
+ option(:full) {
211
+ optional
212
+ desc 'include mirror history' # FIXME
213
+ attr
214
+ }
215
+ }
216
+
217
+ run { help! }
218
+ }
data/braid.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = %q{braid}
3
+ s.version = "0.4.0.1"
4
+
5
+ s.specification_version = 2 if s.respond_to? :specification_version=
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Cristi Balan", "Norbert Crombach"]
9
+ s.date = %q{2008-05-01}
10
+ s.default_executable = %q{braid}
11
+ s.description = %q{Braid is a simple tool to help track git and svn vendor branches in a git repository}
12
+ s.email = %q{evil@che.lu}
13
+ s.executables = ["braid"]
14
+ s.extra_rdoc_files = ["History.txt", "License.txt", "Manifest.txt", "README.txt"]
15
+ s.files = ["History.txt", "License.txt", "Manifest.txt", "README.txt", "Rakefile", "bin/braid", "config/hoe.rb", "config/requirements.rb", "lib/braid.rb", "lib/braid/command.rb", "lib/braid/commands/add.rb", "lib/braid/commands/diff.rb", "lib/braid/commands/remove.rb", "lib/braid/commands/setup.rb", "lib/braid/commands/update.rb", "lib/braid/config.rb", "lib/braid/exceptions.rb", "lib/braid/operations.rb", "lib/braid/version.rb", "braid.gemspec", "script/destroy", "script/generate", "setup.rb", "spec/braid_spec.rb", "spec/config_spec.rb", "spec/operations_spec.rb", "spec/spec.opts", "spec/spec_helper.rb", "tasks/deployment.rake", "tasks/environment.rake", "tasks/rspec.rake", "tasks/website.rake"]
16
+ s.has_rdoc = true
17
+ s.homepage = %q{http://evil.che.lu/projects/braid}
18
+ s.rdoc_options = ["--main", "README.txt"]
19
+ s.require_paths = ["lib"]
20
+ s.rubyforge_project = %q{braid}
21
+ s.rubygems_version = %q{1.1.0}
22
+ s.summary = %q{Braid is a simple tool to help track git and svn vendor branches in a git repository}
23
+
24
+ s.add_dependency(%q<main>, [">= 2.8.0"])
25
+ s.add_dependency(%q<open4>, [">= 0.9.6"])
26
+ end
data/config/hoe.rb ADDED
@@ -0,0 +1,68 @@
1
+ require 'braid/version'
2
+
3
+ AUTHOR = ["Cristi Balan", "Norbert Crombach"]
4
+ EMAIL = "evil@che.lu"
5
+ DESCRIPTION = "Braid is a simple tool to help track git and svn vendor branches in a git repository"
6
+ GEM_NAME = 'braid' # what ppl will type to install your gem
7
+ RUBYFORGE_PROJECT = 'braid' # The unix name for your project
8
+ HOMEPATH = "http://evil.che.lu/projects/braid"
9
+ DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
10
+
11
+ @config_file = "~/.rubyforge/user-config.yml"
12
+ @config = nil
13
+ RUBYFORGE_USERNAME = "unknown"
14
+ def rubyforge_username
15
+ unless @config
16
+ begin
17
+ @config = YAML.load(File.read(File.expand_path(@config_file)))
18
+ rescue
19
+ puts <<-EOS
20
+ ERROR: No rubyforge config file found: #{@config_file}"
21
+ Run 'rubyforge setup' to prepare your env for access to Rubyforge
22
+ - See http://newgem.rubyforge.org/rubyforge.html for more details
23
+ EOS
24
+ exit
25
+ end
26
+ end
27
+ RUBYFORGE_USERNAME.replace @config["username"]
28
+ end
29
+
30
+
31
+ REV = nil
32
+ VERS = Braid::VERSION::STRING + (REV ? ".#{REV}" : "")
33
+ RDOC_OPTS = ['--quiet', '--title', 'braid documentation',
34
+ "--opname", "index.html",
35
+ "--line-numbers",
36
+ "--main", "README",
37
+ "--inline-source"]
38
+
39
+ class Hoe
40
+ def extra_deps
41
+ @extra_deps.reject! { |x| Array(x).first == 'hoe' }
42
+ @extra_deps
43
+ end
44
+ end
45
+
46
+ # Generate all the Rake tasks
47
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
48
+ hoe = Hoe.new(GEM_NAME, VERS) do |p|
49
+ p.author = AUTHOR
50
+ p.description = DESCRIPTION
51
+ p.email = EMAIL
52
+ p.summary = DESCRIPTION
53
+ p.url = HOMEPATH
54
+ p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
55
+ p.test_globs = ["test/**/test_*.rb"]
56
+ p.clean_globs |= ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store'] #An array of file patterns to delete on clean.
57
+
58
+ # == Optional
59
+ p.changes = p.paragraphs_of("History.txt", 0..1).join("\\n\\n")
60
+ p.extra_deps = [ ['main', '>=2.8.0'], ['open4', '>=0.9.6'] ]
61
+
62
+ #p.spec_extras = {} # A hash of extra values to set in the gemspec.
63
+
64
+ end
65
+
66
+ CHANGES = hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n")
67
+ PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
68
+ hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
@@ -0,0 +1,17 @@
1
+ require 'fileutils'
2
+ include FileUtils
3
+
4
+ require 'rubygems'
5
+ %w[rake hoe newgem rubigen main open4].each do |req_gem|
6
+ begin
7
+ require req_gem
8
+ rescue LoadError
9
+ puts "This Rakefile requires the '#{req_gem}' RubyGem."
10
+ puts "Installation: gem install #{req_gem} -y"
11
+ exit
12
+ end
13
+ end
14
+
15
+ $:.unshift(File.join(File.dirname(__FILE__), %w[.. lib]))
16
+
17
+ require 'braid'
@@ -0,0 +1,74 @@
1
+ module Braid
2
+ class Command
3
+ include Operations::Mirror
4
+ include Operations::Helpers
5
+
6
+ class << self
7
+ include Operations::Helpers
8
+ include Operations::Git
9
+
10
+ def run(command, *args)
11
+ raise Braid::Git::GitVersionTooLow unless verify_version("git", REQUIRED_GIT_VERSION)
12
+ raise Braid::Git::GitSvnVersionTooLow unless verify_version("git svn", REQUIRED_GIT_SVN_VERSION)
13
+
14
+ klass = Braid::Commands.const_get(command.to_s.capitalize)
15
+ klass.new.run(*args)
16
+
17
+ rescue Braid::Git::LocalChangesPresent => e
18
+ msg "Local changes are present. You have to commit or stash them before running braid commands."
19
+ msg "Exiting."
20
+
21
+ rescue Braid::Git::GitVersionTooLow => e
22
+ msg "This version of braid requires at least git #{REQUIRED_GIT_VERSION}. You have #{extract_version("git")}."
23
+ msg "Exiting."
24
+
25
+ rescue Braid::Git::GitSvnVersionTooLow => e
26
+ msg "This version of braid requires at least git svn #{REQUIRED_GIT_SVN_VERSION}. You have #{extract_version("git svn")}."
27
+ msg "Exiting."
28
+
29
+ rescue => e
30
+ puts "braid error: " + e.message
31
+ end
32
+
33
+ def msg(str)
34
+ puts str
35
+ end
36
+ end
37
+
38
+ def config
39
+ @config ||= Braid::Config.new
40
+ end
41
+
42
+ private
43
+ def msg(str)
44
+ self.class.msg(str)
45
+ end
46
+
47
+ def in_work_branch
48
+ # make sure there is a git repository
49
+ begin
50
+ old_branch = get_current_branch
51
+ rescue => e
52
+ msg "Error occured: #{e.message}"
53
+ raise e
54
+ end
55
+
56
+ create_work_branch
57
+ work_head = get_work_head
58
+
59
+ begin
60
+ invoke(:git_checkout, WORK_BRANCH)
61
+ yield
62
+ rescue => e
63
+ msg "Error occured: #{e.message}"
64
+ if get_current_branch == WORK_BRANCH
65
+ msg "Resetting '#{WORK_BRANCH}' to '#{work_head}'."
66
+ invoke(:git_reset_hard, work_head)
67
+ end
68
+ raise e
69
+ ensure
70
+ invoke(:git_checkout, old_branch)
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,55 @@
1
+ module Braid
2
+ module Commands
3
+ class Add < Command
4
+ def run(remote, options = {})
5
+ raise Braid::Git::LocalChangesPresent if invoke(:local_changes?)
6
+
7
+ in_work_branch do
8
+ mirror, params = config.add_from_options(remote, options)
9
+ local_branch = get_local_branch_name(mirror, params)
10
+
11
+ config.update(mirror, { "local_branch" => local_branch })
12
+ params["local_branch"] = local_branch # TODO check
13
+
14
+ msg "Adding #{params["type"]} mirror of '#{params["remote"]}'" + (params["type"] == "git" ? ", branch '#{params["branch"]}'" : "") + "."
15
+
16
+ # these commands are explained in the subtree merge guide
17
+ # http://www.kernel.org/pub/software/scm/git/docs/howto/using-merge-subtree.html
18
+
19
+ setup_remote(mirror)
20
+ fetch_remote(params["type"], local_branch)
21
+
22
+ validate_revision_option(params, options)
23
+ target = determine_target_commit(params, options)
24
+
25
+ msg "Merging code into '#{mirror}/'."
26
+
27
+ unless params["squash"]
28
+ invoke(:git_merge_ours, target)
29
+ end
30
+ invoke(:git_read_tree, target, mirror)
31
+
32
+ config.update(mirror, { "revision" => options["revision"] })
33
+ add_config_file
34
+
35
+ revision_message = options["revision"] ? " at #{display_revision(params["type"], options["revision"])}" : ""
36
+ commit_message = "Add mirror '#{mirror}/'#{revision_message}."
37
+ invoke(:git_commit, commit_message)
38
+ end
39
+ end
40
+
41
+ protected
42
+ def setup_remote(mirror)
43
+ Braid::Command.run(:setup, mirror)
44
+ end
45
+
46
+ private
47
+ def get_local_branch_name(mirror, params)
48
+ res = "braid/#{params["type"]}/#{mirror}"
49
+ res << "/#{params["branch"]}" if params["type"] == "git"
50
+ res.gsub!("_", '-') # stupid git svn changes all _ to ., weird
51
+ res
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,10 @@
1
+ module Braid
2
+ module Commands
3
+ class Diff < Command
4
+ def run(mirror)
5
+ # easiest call, liek, evar.
6
+ system("git diff #{WORK_BRANCH} HEAD #{mirror}")
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,27 @@
1
+ module Braid
2
+ module Commands
3
+ class Remove < Command
4
+ def run(mirror)
5
+ raise Braid::Git::LocalChangesPresent if invoke(:local_changes?)
6
+
7
+ in_work_branch do
8
+ params = config.get(mirror)
9
+ unless params
10
+ msg "Mirror '#{mirror}/' does not exist."
11
+ return
12
+ end
13
+
14
+ msg "Removing #{params["type"]} mirror from '#{mirror}/'."
15
+
16
+ invoke(:git_rm_r, mirror)
17
+
18
+ config.remove(mirror)
19
+ add_config_file
20
+
21
+ commit_message = "Remove mirror '#{mirror}/'."
22
+ invoke(:git_commit, commit_message)
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,38 @@
1
+ module Braid
2
+ module Commands
3
+ class Setup < Command
4
+ def run(mirror)
5
+ mirror ? setup_one(mirror) : setup_all
6
+ end
7
+
8
+ protected
9
+ def setup_all
10
+ msg "Setting up all mirrors."
11
+ config.mirrors.each do |mirror|
12
+ setup_one(mirror)
13
+ end
14
+ end
15
+
16
+ def setup_one(mirror)
17
+ params = config.get(mirror)
18
+ unless params
19
+ msg "Mirror '#{mirror}/' does not exist. Skipping."
20
+ return
21
+ end
22
+
23
+ if find_remote(params["local_branch"])
24
+ msg "Mirror '#{mirror}/' already has a remote. Skipping."
25
+ return
26
+ end
27
+
28
+ msg "Setting up remote for '#{mirror}/'."
29
+ case params["type"]
30
+ when "git"
31
+ invoke(:git_remote_add, params["local_branch"], params["remote"], params["branch"])
32
+ when "svn"
33
+ invoke(:git_svn_init, params["local_branch"], params["remote"])
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end