[DRE-commits] [git-up] 01/03: Imported Upstream version 0.5.12
James Lu
glolol-guest at moszumanska.debian.org
Wed Jul 1 03:47:44 UTC 2015
This is an automated email from the git hooks/post-receive script.
glolol-guest pushed a commit to branch master
in repository git-up.
commit 6f757e66c60445220e90a0b9f9033d686b1aa5bc
Author: James Lu <glolol1 at hotmail.com>
Date: Tue Jun 30 20:37:46 2015 -0700
Imported Upstream version 0.5.12
---
LICENSE | 20 +++
README.md | 79 ++++++++++++
bin/git-up | 6 +
lib/git-up.rb | 347 ++++++++++++++++++++++++++++++++++++++++++++++++++
lib/git-up/version.rb | 3 +
man/git-up.1 | 99 ++++++++++++++
metadata.yml | 89 +++++++++++++
7 files changed, 643 insertions(+)
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..d4ff73a
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,20 @@
+Copyright (c) 2009 Aanand Prasad
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..448b3d8
--- /dev/null
+++ b/README.md
@@ -0,0 +1,79 @@
+git-up(1) -- fetch and rebase all locally-tracked remote branches
+=================================================================
+
+SYNOPSIS
+--------
+
+`git pull` has two problems:
+
+* It merges upstream changes by default, when it's really more polite to [rebase over them](http://www.gitready.com/advanced/2009/02/11/pull-with-rebase.html), unless your collaborators enjoy a commit graph that looks like bedhead.
+* It only updates the branch you're currently on, which means `git push` will shout at you for being behind on branches you don't particularly care about right now.
+
+Solve them once and for all.
+
+INSTALL
+-------
+
+ $ gem install git-up
+
+Windows support is predictably absent. Try the [Python port](https://github.com/msiemens/PyGitUp), which was started for that reason.
+
+USE
+---
+
+![$ git up](http://dl.dropbox.com/u/166030/git-up/screenshot.png)
+
+ALTHOUGH
+--------
+
+`git-up` might mess up your branches, or set your chest hair on fire, or be racist to your cat, I don't know. It works for me.
+
+DIFFICULTIES
+------------
+
+### Windows
+Windows support is an ongoing pain. Have a look at [this ticket](https://github.com/aanand/git-up/issues/34) if you really need it, or if you're bored.
+
+### spawn.rb:187:in `_pspawn': Invalid command name (ArgumentError)
+
+If you're using RVM and you get this error, [read this](https://github.com/aanand/git-up/blob/master/RVM.md).
+
+CONFIGURATION
+-------------
+
+`git-up` has a few configuration options, which use git's configuration system. Each can be set either globally or per-project. To set an option globally, append the `--global` flag to `git config`, which you can run anywhere:
+
+ git config --global git-up.bundler.check true
+
+To set it within a project, run the command inside that project's directory and omit the `--global` flag:
+
+ cd myproject
+ git config git-up.bundler.check true
+
+### git-up.bundler.check [true|false]
+
+Default: **false**. If **true**, git-up will check your app for any new bundled gems and suggest a `bundle install` if necessary.
+
+### git-up.bundler.autoinstall [true|false]
+
+Default: **false**. If **true**, and if `git-up.bundler.check` is also set to **true**, git-up will run `bundle install` for you if it finds missing gems.
+
+### git-up.fetch.prune [true|false]
+
+Default: **true**. Append the `--prune` flag when running `git fetch`, if your git version supports it (1.6.6 or greater), telling it to [remove any remote tracking branches which no longer exist on the remote](http://linux.die.net/man/1/git-fetch).
+
+### git-up.fetch.all [true|false]
+
+Default: **false**. Normally, git-up will only fetch remotes for which there is at least one local tracking branch. Setting this option to **true** will make git-up always fetch from all remotes, which is useful if e.g. you use a remote to push to your CI system but never check those branches out.
+
+### git-up.rebase.arguments [string]
+
+Default: **unset**. Additional arguments to pass to `git rebase`. For example, setting this to `--preserve-merges` will recreate your merge commits in the rebased branch.
+
+### git-up.rebase.auto [true|false]
+
+Default: **true**. If this option is set to **false**, git-up will not rebase branches for you. Instead, it will print a message saying they are diverged and let you handle rebasing them later. This can be useful if you have a lot of in-progress work that you don't want to deal with at once, but still want to update other branches.
+
+### git-up.rebase.log-hook "COMMAND"
+
+Default: **unset**. Runs **COMMAND** every time a branch is rebased or fast-forwarded, with the old head as **$1** and the new head as **$2**. This can be used to view logs or diffs of incoming changes. For example: `'echo "changes on $1:"; git log --oneline --decorate $1..$2'`
diff --git a/bin/git-up b/bin/git-up
new file mode 100755
index 0000000..c4ee65f
--- /dev/null
+++ b/bin/git-up
@@ -0,0 +1,6 @@
+#!/usr/bin/env ruby
+
+require 'git-up'
+
+GitUp.new.run(ARGV)
+
diff --git a/lib/git-up.rb b/lib/git-up.rb
new file mode 100644
index 0000000..2ce963c
--- /dev/null
+++ b/lib/git-up.rb
@@ -0,0 +1,347 @@
+require 'colored'
+require 'grit'
+
+require 'git-up/version'
+
+class GitUp
+ def run(argv)
+ process_args(argv)
+
+ command = ['git', 'fetch', '--multiple']
+ command << '--prune' if prune?
+ command += config("fetch.all") ? ['--all'] : remotes
+
+ # puts command.join(" ") # TODO: implement a 'debug' config option
+ system(*command)
+ raise GitError, "`git fetch` failed" unless $? == 0
+ @remote_map = nil # flush cache after fetch
+
+ Grit::Git.with_timeout(0) do
+ with_stash do
+ returning_to_current_branch do
+ rebase_all_branches
+ end
+ end
+ end
+
+ check_bundler
+ rescue GitError => e
+ puts e.message
+ exit 1
+ end
+
+ def process_args(argv)
+ banner = <<BANNER
+Fetch and rebase all remotely-tracked branches.
+
+ $ git up
+ master #{"up to date".green}
+ development #{"rebasing...".yellow}
+ staging #{"fast-forwarding...".yellow}
+ production #{"up to date".green}
+
+ $ git up --version # print version info
+ $ git up --help # print this message
+
+There are no interesting command-line options, but
+there are a few `git config` variables you can set.
+For info on those and more, check out the man page:
+
+ $ git up man
+
+Or install it to your system, so you can get to it with
+`man git-up` or `git help up`:
+
+ $ git up install-man
+
+BANNER
+
+ man_path = File.expand_path('../../man/git-up.1', __FILE__)
+
+ case argv
+ when []
+ return
+ when ["-v"], ["--version"]
+ $stdout.puts "git-up #{GitUp::VERSION}"
+ exit
+ when ["man"]
+ system "man", man_path
+ exit
+ when ["install-man"]
+ destination = "/usr/local/share/man"
+ print "Destination to install man page to [#{destination}]: "
+ override = $stdin.gets.strip
+ destination = override if override.length > 0
+
+ dest_dir = File.join(destination, "man1")
+ dest_path = File.join(dest_dir, File.basename(man_path))
+
+ exit(1) unless system "mkdir", "-p", dest_dir
+ exit(1) unless system "cp", man_path, dest_path
+
+ puts "Installed to #{dest_path}"
+
+ exit
+ when ["-h"], ["--help"]
+ $stderr.puts(banner)
+ exit
+ else
+ $stderr.puts(banner)
+ exit 1
+ end
+ end
+
+ def rebase_all_branches
+ col_width = branches.map { |b| b.name.length }.max + 1
+
+ branches.each do |branch|
+ remote = remote_map[branch.name]
+
+ curbranch = branch.name.ljust(col_width)
+ if branch.name == repo.head.name
+ print curbranch.bold
+ else
+ print curbranch
+ end
+
+ if remote.commit.sha == branch.commit.sha
+ puts "up to date".green
+ next
+ end
+
+ base = merge_base(branch.name, remote.name)
+
+ if base == remote.commit.sha
+ puts "ahead of upstream".green
+ next
+ end
+
+ if base == branch.commit.sha
+ puts "fast-forwarding...".yellow
+ elsif config("rebase.auto") == 'false'
+ puts "diverged".red
+ next
+ else
+ puts "rebasing...".yellow
+ end
+
+ log(branch, remote)
+ checkout(branch.name)
+ rebase(remote)
+ end
+ end
+
+ def repo
+ @repo ||= get_repo
+ end
+
+ def get_repo
+ repo_dir = `git rev-parse --show-toplevel`.chomp
+
+ if $? == 0
+ Dir.chdir repo_dir
+ @repo = Grit::Repo.new(repo_dir)
+ else
+ raise GitError, "We don't seem to be in a git repository."
+ end
+ end
+
+ def branches
+ @branches ||= repo.branches.select { |b| remote_map.has_key?(b.name) }.sort_by { |b| b.name }
+ end
+
+ def remotes
+ @remotes ||= remote_map.values.map { |r| r.name.split('/', 2).first }.uniq
+ end
+
+ def remote_map
+ @remote_map ||= repo.branches.inject({}) { |map, branch|
+ if remote = remote_for_branch(branch)
+ map[branch.name] = remote
+ end
+
+ map
+ }
+ end
+
+ def remote_for_branch(branch)
+ remote_name = repo.config["branch.#{branch.name}.remote"] || "origin"
+ remote_branch = repo.config["branch.#{branch.name}.merge"] || branch.name
+ remote_branch.sub!(%r{^refs/heads/}, '')
+ repo.remotes.find { |r| r.name == "#{remote_name}/#{remote_branch}" }
+ end
+
+ def with_stash
+ stashed = false
+
+ if change_count > 0
+ puts "stashing #{change_count} changes".magenta
+ repo.git.stash
+ stashed = true
+ end
+
+ yield
+
+ if stashed
+ puts "unstashing".magenta
+ repo.git.stash({}, "pop")
+ end
+ end
+
+ def returning_to_current_branch
+ unless repo.head.respond_to?(:name)
+ puts "You're not currently on a branch. I'm exiting in case you're in the middle of something.".red
+ return
+ end
+
+ branch_name = repo.head.name
+
+ yield
+
+ unless on_branch?(branch_name)
+ puts "returning to #{branch_name}".magenta
+ checkout(branch_name)
+ end
+ end
+
+ def checkout(branch_name)
+ output = repo.git.checkout({}, branch_name)
+
+ unless on_branch?(branch_name)
+ raise GitError.new("Failed to checkout #{branch_name}", output)
+ end
+ end
+
+ def log(branch, remote)
+ if log_hook = config("rebase.log-hook")
+ system('sh', '-c', log_hook, 'git-up', branch.name, remote.name)
+ end
+ end
+
+ def rebase(target_branch)
+ current_branch = repo.head
+ arguments = config("rebase.arguments")
+
+ output, err = repo.git.sh("#{Grit::Git.git_binary} rebase #{arguments} #{target_branch.name}")
+
+ unless on_branch?(current_branch.name) and is_fast_forward?(current_branch, target_branch)
+ raise GitError.new("Failed to rebase #{current_branch.name} onto #{target_branch.name}", output+err)
+ end
+ end
+
+ def check_bundler
+ return unless use_bundler?
+
+ begin
+ require 'bundler'
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('Gemfile')
+ Gem.loaded_specs.clear
+ Bundler.setup
+ rescue Bundler::GemNotFound, Bundler::GitError
+ puts
+ print 'Gems are missing. '.yellow
+
+ if config("bundler.autoinstall") == 'true'
+ puts "Running `bundle install`.".yellow
+ system "bundle", "install"
+ else
+ puts "You should `bundle install`.".yellow
+ end
+ end
+ end
+
+ def is_fast_forward?(a, b)
+ merge_base(a.name, b.name) == b.commit.sha
+ end
+
+ def merge_base(a, b)
+ repo.git.send("merge-base", {}, a, b).strip
+ end
+
+ def on_branch?(branch_name=nil)
+ repo.head.respond_to?(:name) and repo.head.name == branch_name
+ end
+
+ class GitError < StandardError
+ def initialize(message, output=nil)
+ @msg = "#{message.red}"
+
+ if output
+ @msg << "\n"
+ @msg << "Here's what Git said:".red
+ @msg << "\n"
+ @msg << output
+ end
+ end
+
+ def message
+ @msg
+ end
+ end
+
+private
+
+ def use_bundler?
+ use_bundler_config? and File.exists? 'Gemfile'
+ end
+
+ def use_bundler_config?
+ if ENV.has_key?('GIT_UP_BUNDLER_CHECK')
+ puts <<-EOS.yellow
+The GIT_UP_BUNDLER_CHECK environment variable is deprecated.
+You can now tell git-up to check (or not check) for missing
+gems on a per-project basis using git's config system. To
+set it globally, run this command anywhere:
+
+ git config --global git-up.bundler.check true
+
+To set it within a project, run this command inside that
+project's directory:
+
+ git config git-up.bundler.check true
+
+Replace 'true' with 'false' to disable checking.
+EOS
+ end
+
+ config("bundler.check") == 'true' || ENV['GIT_UP_BUNDLER_CHECK'] == 'true'
+ end
+
+ def prune?
+ required_version = "1.6.6"
+ config_value = config("fetch.prune")
+
+ if git_version_at_least?(required_version)
+ config_value != 'false'
+ else
+ if config_value == 'true'
+ puts "Warning: fetch.prune is set to 'true' but your git version doesn't seem to support it (#{git_version} < #{required_version}). Defaulting to 'false'.".yellow
+ end
+
+ false
+ end
+ end
+
+ def change_count
+ @change_count ||= begin
+ repo.git.status(:porcelain => true, :'untracked-files' => 'no').split("\n").count
+ end
+ end
+
+ def config(key)
+ repo.config["git-up.#{key}"]
+ end
+
+ def git_version_at_least?(required_version)
+ (version_array(git_version) <=> version_array(required_version)) >= 0
+ end
+
+ def version_array(version_string)
+ version_string.split('.').map { |s| s.to_i }
+ end
+
+ def git_version
+ `git --version`[/\d+(\.\d+)+/]
+ end
+end
+
diff --git a/lib/git-up/version.rb b/lib/git-up/version.rb
new file mode 100644
index 0000000..6248384
--- /dev/null
+++ b/lib/git-up/version.rb
@@ -0,0 +1,3 @@
+class GitUp
+ VERSION = "0.5.12"
+end
diff --git a/man/git-up.1 b/man/git-up.1
new file mode 100644
index 0000000..254a6e7
--- /dev/null
+++ b/man/git-up.1
@@ -0,0 +1,99 @@
+.\" generated with Ronn/v0.7.3
+.\" http://github.com/rtomayko/ronn/tree/0.7.3
+.
+.TH "GIT\-UP" "1" "July 2013" "" ""
+.
+.SH "NAME"
+\fBgit\-up\fR \- fetch and rebase all locally\-tracked remote branches
+.
+.SH "SYNOPSIS"
+\fBgit pull\fR has two problems:
+.
+.IP "\(bu" 4
+It merges upstream changes by default, when it\'s really more polite to rebase over them \fIhttp://www\.gitready\.com/advanced/2009/02/11/pull\-with\-rebase\.html\fR, unless your collaborators enjoy a commit graph that looks like bedhead\.
+.
+.IP "\(bu" 4
+It only updates the branch you\'re currently on, which means \fBgit push\fR will shout at you for being behind on branches you don\'t particularly care about right now\.
+.
+.IP "" 0
+.
+.P
+Solve them once and for all\.
+.
+.SH "INSTALL"
+.
+.nf
+
+$ gem install git\-up
+.
+.fi
+.
+.P
+Windows support is predictably absent\. Try the Python port \fIhttps://github\.com/msiemens/PyGitUp\fR, which was started for that reason\.
+.
+.SH "USE"
+.
+.nf
+
+$ git up
+.
+.fi
+.
+.SH "ALTHOUGH"
+\fBgit\-up\fR might mess up your branches, or set your chest hair on fire, or be racist to your cat, I don\'t know\. It works for me\.
+.
+.SH "DIFFICULTIES"
+.
+.SS "Windows"
+Windows support is an ongoing pain\. Have a look at this ticket \fIhttps://github\.com/aanand/git\-up/issues/34\fR if you really need it, or if you\'re bored\.
+.
+.SS "spawn\.rb:187:in `_pspawn\': Invalid command name (ArgumentError)"
+If you\'re using RVM and you get this error, read this \fIhttps://github\.com/aanand/git\-up/blob/master/RVM\.md\fR\.
+.
+.SH "CONFIGURATION"
+\fBgit\-up\fR has a few configuration options, which use git\'s configuration system\. Each can be set either globally or per\-project\. To set an option globally, append the \fB\-\-global\fR flag to \fBgit config\fR, which you can run anywhere:
+.
+.IP "" 4
+.
+.nf
+
+git config \-\-global git\-up\.bundler\.check true
+.
+.fi
+.
+.IP "" 0
+.
+.P
+To set it within a project, run the command inside that project\'s directory and omit the \fB\-\-global\fR flag:
+.
+.IP "" 4
+.
+.nf
+
+cd myproject
+git config git\-up\.bundler\.check true
+.
+.fi
+.
+.IP "" 0
+.
+.SS "git\-up\.bundler\.check [true|false]"
+Default: \fBfalse\fR\. If \fBtrue\fR, git\-up will check your app for any new bundled gems and suggest a \fBbundle install\fR if necessary\.
+.
+.SS "git\-up\.bundler\.autoinstall [true|false]"
+Default: \fBfalse\fR\. If \fBtrue\fR, and if \fBgit\-up\.bundler\.check\fR is also set to \fBtrue\fR, git\-up will run \fBbundle install\fR for you if it finds missing gems\.
+.
+.SS "git\-up\.fetch\.prune [true|false]"
+Default: \fBtrue\fR\. Append the \fB\-\-prune\fR flag when running \fBgit fetch\fR, if your git version supports it (1\.6\.6 or greater), telling it to remove any remote tracking branches which no longer exist on the remote \fIhttp://linux\.die\.net/man/1/git\-fetch\fR\.
+.
+.SS "git\-up\.fetch\.all [true|false]"
+Default: \fBfalse\fR\. Normally, git\-up will only fetch remotes for which there is at least one local tracking branch\. Setting this option to \fBtrue\fR will make git\-up always fetch from all remotes, which is useful if e\.g\. you use a remote to push to your CI system but never check those branches out\.
+.
+.SS "git\-up\.rebase\.arguments [string]"
+Default: \fBunset\fR\. Additional arguments to pass to \fBgit rebase\fR\. For example, setting this to \fB\-\-preserve\-merges\fR will recreate your merge commits in the rebased branch\.
+.
+.SS "git\-up\.rebase\.auto [true|false]"
+Default: \fBtrue\fR\. If this option is set to \fBfalse\fR, git\-up will not rebase branches for you\. Instead, it will print a message saying they are diverged and let you handle rebasing them later\. This can be useful if you have a lot of in\-progress work that you don\'t want to deal with at once, but still want to update other branches\.
+.
+.SS "git\-up\.rebase\.log\-hook \"COMMAND\""
+Default: \fBunset\fR\. Runs \fBCOMMAND\fR every time a branch is rebased or fast\-forwarded, with the old head as \fB$1\fR and the new head as \fB$2\fR\. This can be used to view logs or diffs of incoming changes\. For example: \fB\'echo "changes on $1:"; git log \-\-oneline \-\-decorate $1\.\.$2\'\fR
diff --git a/metadata.yml b/metadata.yml
new file mode 100644
index 0000000..f75cd09
--- /dev/null
+++ b/metadata.yml
@@ -0,0 +1,89 @@
+--- !ruby/object:Gem::Specification
+name: git-up
+version: !ruby/object:Gem::Version
+ version: 0.5.12
+ prerelease:
+platform: ruby
+authors:
+- Aanand Prasad
+- Elliot Crosby-McCullough
+- Adrian Irving-Beer
+- Joshua Wehner
+autorequire:
+bindir: bin
+cert_chain: []
+date: 2013-07-23 00:00:00.000000000 Z
+dependencies:
+- !ruby/object:Gem::Dependency
+ name: colored
+ requirement: !ruby/object:Gem::Requirement
+ none: false
+ requirements:
+ - - ! '>='
+ - !ruby/object:Gem::Version
+ version: '1.2'
+ type: :runtime
+ prerelease: false
+ version_requirements: !ruby/object:Gem::Requirement
+ none: false
+ requirements:
+ - - ! '>='
+ - !ruby/object:Gem::Version
+ version: '1.2'
+- !ruby/object:Gem::Dependency
+ name: grit
+ requirement: !ruby/object:Gem::Requirement
+ none: false
+ requirements:
+ - - ! '>='
+ - !ruby/object:Gem::Version
+ version: '0'
+ type: :runtime
+ prerelease: false
+ version_requirements: !ruby/object:Gem::Requirement
+ none: false
+ requirements:
+ - - ! '>='
+ - !ruby/object:Gem::Version
+ version: '0'
+description:
+email:
+- aanand.prasad at gmail.com
+- elliot.cm at gmail.com
+executables:
+- git-up
+extensions: []
+extra_rdoc_files: []
+files:
+- bin/git-up
+- lib/git-up/version.rb
+- lib/git-up.rb
+- man/git-up.1
+- LICENSE
+- README.md
+homepage: http://github.com/aanand/git-up
+licenses:
+- MIT
+post_install_message:
+rdoc_options: []
+require_paths:
+- lib
+required_ruby_version: !ruby/object:Gem::Requirement
+ none: false
+ requirements:
+ - - ! '>='
+ - !ruby/object:Gem::Version
+ version: '0'
+required_rubygems_version: !ruby/object:Gem::Requirement
+ none: false
+ requirements:
+ - - ! '>='
+ - !ruby/object:Gem::Version
+ version: '0'
+requirements: []
+rubyforge_project:
+rubygems_version: 1.8.23
+signing_key:
+specification_version: 3
+summary: git command to fetch and rebase all branches
+test_files: []
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ruby-extras/git-up.git
More information about the Pkg-ruby-extras-commits
mailing list