lib/git-up.rb in git-up-0.5.2 vs lib/git-up.rb in git-up-0.5.3
- old
+ new
@@ -1,51 +1,62 @@
require 'colored'
require 'grit'
class GitUp
def run
- system('git', 'fetch', '--multiple', *remotes)
+ command = ['git', 'fetch', '--multiple']
+ command << '--prune' if prune?
+ command += 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
- with_stash do
- returning_to_current_branch do
- col_width = branches.map { |b| b.name.length }.max + 1
+ Grit::Git.with_timeout(0) do
+ with_stash do
+ returning_to_current_branch do
+ rebase_all_branches
+ end
+ end
+ end
- branches.each do |branch|
- remote = remote_map[branch.name]
+ check_bundler
+ rescue GitError => e
+ puts e.message
+ exit 1
+ end
- print branch.name.ljust(col_width)
+ def rebase_all_branches
+ col_width = branches.map { |b| b.name.length }.max + 1
- if remote.commit.sha == branch.commit.sha
- puts "up to date".green
- next
- end
+ branches.each do |branch|
+ remote = remote_map[branch.name]
- base = merge_base(branch.name, remote.name)
+ print branch.name.ljust(col_width)
- if base == remote.commit.sha
- puts "ahead of upstream".green
- next
- end
+ if remote.commit.sha == branch.commit.sha
+ puts "up to date".green
+ next
+ end
- if base == branch.commit.sha
- puts "fast-forwarding...".yellow
- else
- puts "rebasing...".yellow
- end
+ base = merge_base(branch.name, remote.name)
- checkout(branch.name)
- rebase(remote)
- end
+ if base == remote.commit.sha
+ puts "ahead of upstream".green
+ next
end
- end
- check_bundler
- rescue GitError => e
- puts e.message
- exit 1
+ if base == branch.commit.sha
+ puts "fast-forwarding...".yellow
+ else
+ puts "rebasing...".yellow
+ end
+
+ checkout(branch.name)
+ rebase(remote)
+ end
end
def repo
@repo ||= get_repo
end
@@ -216,10 +227,29 @@
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 < required_version
+ 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
+ else
+ config_value != 'false'
+ end
+ end
+
def config(key)
repo.config["git-up.#{key}"]
+ end
+
+ def git_version
+ `git --version`[/\d+(\.\d+)+/]
end
end