From 02ee5bf4434f95eac609cd59cb4bec6b61317c7a Mon Sep 17 00:00:00 2001 From: Chris Wanstrath Date: Tue, 8 Dec 2009 20:10:42 -0800 Subject: [PATCH] update standalone --- standalone | 363 +++++++++++++++++++++++++++++++++++++++++++++++++ standalone.md5 | 1 + 2 files changed, 364 insertions(+) create mode 100755 standalone create mode 100644 standalone.md5 diff --git a/standalone b/standalone new file mode 100755 index 00000000..462f2b18 --- /dev/null +++ b/standalone @@ -0,0 +1,363 @@ +#!/usr/bin/env ruby +# +# This file, hub, is generated code. +# Please DO NOT EDIT or send patches for it. +# +# Please take a look at the source from +# http://github.com/defunkt/hub +# and submit patches against the individual files +# that build hub. +# + +module Hub + class Args < Array + def after(command = nil, &block) + @after ||= block ? block : command + end + + def after? + !!@after + end + end +end +module Colored + extend self + + COLORS = { + 'black' => 30, + 'red' => 31, + 'green' => 32, + 'yellow' => 33, + 'blue' => 34, + 'magenta' => 35, + 'cyan' => 36, + 'white' => 37 + } + + EXTRAS = { + 'clear' => 0, + 'bold' => 1, + 'underline' => 4, + 'reversed' => 7 + } + + COLORS.each do |color, value| + define_method(color) do + colorize(self, :foreground => color) + end + + define_method("on_#{color}") do + colorize(self, :background => color) + end + + COLORS.each do |highlight, value| + next if color == highlight + define_method("#{color}_on_#{highlight}") do + colorize(self, :foreground => color, :background => highlight) + end + end + end + + EXTRAS.each do |extra, value| + next if extra == 'clear' + define_method(extra) do + colorize(self, :extra => extra) + end + end + + define_method(:to_eol) do + tmp = sub(/^(\e\[[\[\e0-9;m]+m)/, "\\1\e[2K") + if tmp == self + return "\e[2K" << self + end + tmp + end + + def colorize(string, options = {}) + return string unless $stdout.tty? + colored = [color(options[:foreground]), color("on_#{options[:background]}"), extra(options[:extra])].compact * '' + colored << string + colored << extra(:clear) + end + + def colors + @@colors ||= COLORS.keys.sort + end + + def extra(extra_name) + extra_name = extra_name.to_s + "\e[#{EXTRAS[extra_name]}m" if EXTRAS[extra_name] + end + + def color(color_name) + background = color_name.to_s =~ /on_/ + color_name = color_name.to_s.sub('on_', '') + return unless color_name && COLORS[color_name] + "\e[#{COLORS[color_name] + (background ? 10 : 0)}m" + end +end unless Object.const_defined? :Colored + +String.send(:include, Colored) +module Hub + module Commands + instance_methods.each { |m| undef_method(m) unless m =~ /(^__|send|to\?$)/ } + extend self + + PRIVATE = 'git@github.com:%s/%s.git' + PUBLIC = 'git://github.com/%s/%s.git' + USER = `git config --global github.user`.chomp + REPO = `basename $(pwd)`.chomp + + def clone(args) + ssh = args.delete('-p') + args.each_with_index do |arg, i| + if arg.scan('/').size == 1 && !arg.include?(':') + url = ssh ? PRIVATE : PUBLIC + args[i] = url % arg.split('/') + end + end + end + + def remote(args) + return unless args[1] == 'add' + + if args[-1] !~ /:\// + ssh = args.delete('-p') + user = args.last + url = ssh ? PRIVATE : PUBLIC + args << url % [ user, REPO ] + end + end + + def init(args) + if args.delete('-g') + url = PRIVATE % [ USER, REPO ] + args.after "git remote add origin #{url}" + end + end + + def alias(args) + shells = { + 'sh' => 'alias git=hub', + 'bash' => 'alias git=hub', + 'zsh' => 'alias git=hub', + 'csh' => 'alias git hub', + 'fish' => 'alias git hub' + } + + silent = args.delete('-s') + + if shell = args[1] + if silent.nil? + puts "Run this in your shell to start using `hub` as `git`:" + print " " + end + else + puts "usage: hub alias [-s] SHELL", "" + puts "You already have hub installed and available in your PATH," + puts "but to get the full experience you'll want to alias it to" + puts "`git`.", "" + puts "To see how to accomplish this for your shell, run the alias" + puts "command again with the name of your shell.", "" + puts "Known shells:" + shells.map { |key, _| key }.sort.each do |key| + puts " " + key + end + puts "", "Options:" + puts " -s Silent. Useful when using the output with eval, e.g." + puts " $ eval `hub alias -s bash`" + + exit + end + + if shells[shell] + puts shells[shell] + else + abort "fatal: never heard of `#{shell}'" + end + + exit + end + + def version(args) + args.after do + puts "hub version %s" % Version + end + end + alias_method "--version", :version + + def help(args) + return if args.size > 1 + puts improved_help_text + exit + end + + def improved_help_text + <<-help +usage: git [--version] [--exec-path[=GIT_EXEC_PATH]] [--html-path] + [-p|--paginate|--no-pager] [--bare] [--git-dir=GIT_DIR] + [--work-tree=GIT_WORK_TREE] [--help] COMMAND [ARGS] + +Creating a git repository: + clone Clone a repository into a new directory + init Create an empty git repository or reinitialize an existing one + +Working with content: + add Add file contents to the index + branch List, create, or delete branches + checkout Checkout a branch or paths to the working tree + commit Record changes to the repository + diff Show changes between commits, commit and working tree, etc + log Show commit logs + merge Join two or more development histories together + mv Move or rename a file, a directory, or a symlink + rm Remove files from the working tree and from the index + status Show the working tree status + show Show various types of objects + tag Create, list, delete or verify a tag object signed with GPG + +Over the network: + fetch Download objects and refs from another repository + pull Fetch from and merge with another repository or a local branch + push Update remote refs along with associated objects + remote Manage a set of tracked repositories + +Advanced commands: + bisect Find by binary search the change that introduced a bug + grep Print lines matching a pattern + reset Reset current HEAD to the specified state + rebase Forward-port local commits to the updated upstream head + +See 'git help COMMAND' for more information on a specific command. +help + end + + def install(args) + command, subcommand, target = args + + if subcommand.to_s == 'standalone' + Standalone.save('hub', target.empty? ? '.' : target) + elsif subcommand.to_s == 'check' + begin + if up_to_date? + puts "*".green + " hub is up to date" + else + puts "*".red + " hub is " + "not".bold.underline + " up to date" + end + rescue Object => e + puts "*".bold.yellow + " error checking status: #{e.class}" + end + else + puts <<-output +usage: hub install COMMAND [ARGS] + +Commands: + standalone Installs the standalone `hub` script locally. If + a path is provided, attempts to install it there. + If not path is provided asks you to choose from + possible install locations. + + check Checks if the current installation is up to date + by phoning home. +output + end + + exit + end + + private + + def up_to_date? + latest_md5 == current_md5 + end + + def latest_md5 + require 'open-uri' + md5_url = "http://defunkt.github.com/hub/standalone.md5" + md5 = open(md5_url).read.chomp + end + + def current_md5 + require 'digest/md5' + hub = defined?(Standalone) ? Standalone.build : File.read(__FILE__) + Digest::MD5.hexdigest(hub) + end + + def puts(*args) + page_stdout + super + end + + def page_stdout + return unless $stdout.tty? + + read, write = IO.pipe + + if Kernel.fork + $stdin.reopen(read) + read.close + write.close + + ENV['LESS'] = 'FSRX' + + Kernel.select [STDIN] + + pager = ENV['PAGER'] || 'less' + exec pager rescue exec "/bin/sh", "-c", pager + else + $stdout.reopen(write) + $stderr.reopen(write) if $stderr.tty? + read.close + write.close + end + end + end +end +module Hub + class Runner + attr_reader :args + def initialize(*args) + @args = Args.new(args) + + @args[0] = 'help' if @args.empty? + + if Commands.respond_to?(@args[0]) + Commands.send(@args[0], @args) + end + end + + def self.execute(*args) + new(*args).execute + end + + def after + args.after.to_s + end + + def command + "git #{args.join(' ')}" + end + + def execute + if args.after? + execute_with_after_callback + else + exec "git", *args + end + end + + def execute_with_after_callback + after = args.after + if system("git", *args) + after.respond_to?(:call) ? after.call : exec(after) + exit + else + exit 1 + end + end + end +end +module Hub + Version = '0.1.0' +end +Hub::Runner.execute(*ARGV) diff --git a/standalone.md5 b/standalone.md5 new file mode 100644 index 00000000..5ee07bc8 --- /dev/null +++ b/standalone.md5 @@ -0,0 +1 @@ +edb48bf5983bfd40765e905cb1c6dd7a -- GitLab