#!/usr/bin/env ruby $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + '/../lib')) require 'braid' require 'rubygems' require 'main' Home = File.expand_path(ENV['HOME'] || '~') # mostly blantantly stolen from ara's punch script # main kicks ass! Main { description <<-TXT braid is a simple tool to help track git repositories inside a git repository. Run 'braid commandname help' for more details. All operations will be executed in the braid/track branch. You can then merge back or cherry-pick changes. TXT mode(:add) { description <<-TXT Add a new mirror to be tracked. * adds metadata about the mirror to .braids.json * adds the git remotes to .git/config * fetches and merges remote code into given directory Name defaults: * remote/path # => path * remote/path/trunk # => path * remote/path.git # => path TXT examples <<-TXT . braid add http://remote/path.git local/dir . braid add http://remote/path local/dir TXT mixin :argument_url, :optional_local_path, :option_branch, :option_revision, :option_verbose, :option_path run { Braid.verbose = verbose Braid::Command.run(:add, url, {'path' => local_path, 'branch' => branch, 'revision' => revision, 'remote_path' => path}) } } mode(:update) { description <<-TXT Update a braid mirror. * get new changes from remote * always creates a merge commit * updates metadata in .braids.json when revisions are changed * removes the git remote by default, --keep can be used to suppress that Defaults to updating all unlocked mirrors if none is specified. TXT examples <<-TXT . braid update . braid update local/dir TXT mixin :optional_local_path, :option_revision, :option_head, :option_verbose, :option_keep_remote run { options = { 'revision' => revision, 'head' => head, 'keep' => keep } Braid.verbose = verbose Braid::Command.run(:update, local_path, options) } } mode(:remove) { description <<-TXT Remove a mirror. * removes metadata from .braids.json * removes the local directory and commits the removal * removes the git remote by default, --keep can be used to suppress that TXT examples <<-TXT . braid remove local/dir TXT mixin :argument_local_path, :option_verbose, :option_keep_remote run { options = { :keep => keep } Braid.verbose = verbose Braid::Command.run(:remove, local_path, options) } } mode(:diff) { description <<-TXT Show diff of local changes to mirror. TXT mixin :optional_local_path, :option_verbose, :option_keep_remote run { options = { 'keep' => keep } Braid.verbose = verbose Braid::Command.run(:diff, local_path, options) } } mode(:push) { description <<-TXT Push local mirror changes to remote. TXT mixin :argument_local_path, :option_branch, :option_verbose, :option_keep_remote run { options = { 'keep' => keep, 'branch' => branch } Braid.verbose = verbose Braid::Command.run(:push, local_path, options) } } mode(:setup) { description <<-TXT Set up git remotes. TXT mixin :optional_local_path, :option_verbose, :option_force run { Braid.verbose = verbose Braid.force = force Braid::Command.run(:setup, local_path) } } mode(:version) { description 'Show braid version.' run { puts "braid #{Braid::VERSION}" } } mode(:status) { description 'Show the status of all tracked mirrors (and if updates are available).' mixin :optional_local_path, :option_verbose run { Braid.verbose = verbose Braid::Command.run(:status, local_path) } } mixin(:argument_local_path) { argument(:local_path) { attr } } mixin(:optional_local_path) { argument(:local_path) { optional attr } } mixin(:argument_url) { argument(:url) { attr } } mixin(:option_branch) { option(:branch, :b) { optional argument :required desc 'remote branch name' attr } } mixin(:option_path) { option(:path, :p) { optional argument :required desc 'remote path' attr } } mixin(:option_revision) { option(:revision, :r) { optional argument :required desc 'revision to track' attr } } mixin(:option_head) { option(:head) { optional desc 'mirror head' attr } } mixin(:option_verbose) { option(:verbose, :v) { optional desc 'log shell commands' attr } } mixin(:option_force) { option(:force, :f) { optional desc 'force' attr } } mixin(:option_keep_remote) { option(:keep) { optional desc 'do not remove the remote' attr } } run { help! } }