Permalink
Browse files

Oh snap, push works

  • Loading branch information...
1 parent 1b35d99 commit a2e1320da49f661e8f3eaca25eb0e3a11da9d42d @norbert norbert committed Nov 13, 2008
Showing with 81 additions and 28 deletions.
  1. +19 −17 bin/braid
  2. +47 −0 lib/braid/commands/push.rb
  3. +1 −1 lib/braid/commands/update.rb
  4. +1 −1 lib/braid/mirror.rb
  5. +13 −9 lib/braid/operations.rb
View
@@ -107,39 +107,41 @@ Main {
}
}
- mode(:setup) {
+ mode(:diff) {
description <<-TXT
- Set up git or git-svn remote for a mirror.
- All commands that need a remote run setup internally.
-
- Defaults to setting up remotes for all mirrors if none is specified.
+ Show diff of local changes to mirror.
TXT
- examples <<-TXT
- . braid setup local/dir
+ mixin :argument_path, :option_verbose
+
+ run {
+ Braid::Command.run(:diff, path)
+ }
+ }
+
+ mode(:push) {
+ description <<-TXT
+ Push local mirror changes to remote.
TXT
- mixin :optional_path, :option_verbose
+ mixin :argument_path, :option_verbose
run {
Braid.verbose = verbose
- Braid::Command.run(:setup, path)
+ Braid::Command.run(:push, path)
}
}
- mode(:diff) {
+ mode(:setup) {
description <<-TXT
- Show diff of local changes to mirror.
+ Set up git and git-svn remotes.
TXT
- examples <<-TXT
- . braid diff local/dir
- TXT
-
- mixin :argument_path, :option_verbose
+ mixin :optional_path, :option_verbose
run {
- Braid::Command.run(:diff, path)
+ Braid.verbose = verbose
+ Braid::Command.run(:setup, path)
}
}
View
@@ -0,0 +1,47 @@
+require 'fileutils'
+require 'tmpdir'
+
+module Braid
+ module Commands
+ class Push < Command
+ def run(path, options = {})
+ mirror = config.get!(path)
+
+ #mirror.fetch
+
+ base_revision = git.rev_parse(mirror.remote)
+ unless mirror.merged?(base_revision)
+ msg "Mirror is not up to date. Stopping."
+ return
+ end
+
+ diff = mirror.diff
+ if diff.empty?
+ msg "No local changes found. Stopping."
+ return
+ end
+
+ clone_dir = Dir.tmpdir + "/braid_push.#{$$}"
+ Dir.mkdir(clone_dir)
+ source_dir = Dir.pwd
+ remote_url = git.remote_url(mirror.remote)
+ if File.directory?(remote_url)
+ remote_url = File.expand_path(remote_url)
+ end
+ STDOUT.puts remote_url
+ Dir.chdir(clone_dir) do
+ msg "Cloning mirror with local changes."
+ git.init
+ git.fetch(source_dir)
+ git.fetch(remote_url)
+ git.checkout(base_revision)
+ git.apply(diff)
+ system("git commit -v")
+ msg "Pushing changes to remote."
+ git.push(remote_url, "HEAD:#{mirror.branch}")
+ end
+ FileUtils.rm_r(clone_dir)
+ end
+ end
+ end
+end
@@ -59,7 +59,7 @@ def update_one(path, options = {})
begin
if mirror.squashed?
local_hash = git.rev_parse("HEAD")
- if diff
+ if !diff.empty?
base_hash = generate_tree_hash(mirror, base_revision)
else
base_hash = local_hash
View
@@ -86,7 +86,7 @@ def merged?(commit)
def diff
remote_hash = git.rev_parse("#{base_revision}:")
local_hash = git.tree_hash(path)
- remote_hash != local_hash ? git.diff_tree(remote_hash, local_hash, path) : ""
+ remote_hash != local_hash ? git.diff_tree(remote_hash, local_hash) : ""
end
def fetch
View
@@ -139,12 +139,16 @@ def verbose?
class Git < Proxy
def commit(message, *args)
-
- commit_message_file = Tempfile.new("braid_commit", ".")
- commit_message_file.print("Braid: " + message)
- commit_message_file.flush
- status, out, err = exec("git commit -F #{commit_message_file.path} --no-verify #{args.join(' ')}")
- commit_message_file.unlink
+ cmd = "git commit --no-verify"
+ if message # allow nil
+ message_file = Tempfile.new("braid_commit")
+ message_file.print(message)
+ message_file.flush
+ cmd << " -F #{message_file.path}"
+ end
+ cmd << " #{args.join(' ')}" unless args.empty?
+ status, out, err = exec(cmd)
+ message_file.unlink if message_file
if status == 0
true
@@ -155,10 +159,10 @@ def commit(message, *args)
end
end
- def fetch(remote = nil)
- args = remote && "-n #{remote}"
+ def fetch(remote = nil, *args)
+ args.unshift "-n #{remote}" if remote
# open4 messes with the pipes of index-pack
- sh("git fetch #{args} 2>&1 >/dev/null")
+ sh("git fetch #{args.join(' ')} 2>&1 >/dev/null")
end
def checkout(treeish)

0 comments on commit a2e1320

Please sign in to comment.