git-up-decklin 0.5.1.1 → 0.5.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +15 -6
- data/bin/git-up +1 -0
- data/lib/git-up.rb +100 -54
- data/lib/git-up/version.rb +1 -1
- metadata +24 -9
data/README.md
CHANGED
@@ -15,16 +15,25 @@ although
|
|
15
15
|
configuration
|
16
16
|
-------------
|
17
17
|
|
18
|
-
`git-up` can
|
19
|
-
|
20
|
-
It slows the process down slightly, and is therefore enabled by setting `git-up.bundler.check` to `true` in your git config, either globally or per-project. To set it globally, run this command anywhere:
|
18
|
+
`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:
|
21
19
|
|
22
20
|
git config --global git-up.bundler.check true
|
23
21
|
|
24
|
-
To set it within a project, run
|
22
|
+
To set it within a project, run the command inside that project's directory and omit the `--global` flag:
|
25
23
|
|
24
|
+
cd myproject
|
26
25
|
git config git-up.bundler.check true
|
27
26
|
|
28
|
-
|
27
|
+
### `git-up.bundler.check [true|false]`
|
28
|
+
|
29
|
+
If set to `true`, `git-up` will check your app for any new bundled gems and suggest a `bundle install` if necessary.
|
30
|
+
|
31
|
+
It slows the process down slightly, and therefore defaults to `false`.
|
32
|
+
|
33
|
+
### `git-up.bundler.autoinstall [true|false]`
|
34
|
+
|
35
|
+
If you're even lazier, you can tell `git-up` to run `bundle install` for you if it finds missing gems. Make sure `git-up.bundler.check` is also set to `true` or it won't do anything.
|
36
|
+
|
37
|
+
### `git-up.fetch.prune [true|false]`
|
29
38
|
|
30
|
-
|
39
|
+
By default, `git-up` will append the `--prune` flag to the `git fetch` command if your git version supports it (1.6.6 or greater), telling it to [delete any branches which no longer exist on the remote](http://linux.die.net/man/1/git-fetch). Set this option to `false` to disable it.
|
data/bin/git-up
CHANGED
data/lib/git-up.rb
CHANGED
@@ -3,48 +3,20 @@ require 'grit'
|
|
3
3
|
|
4
4
|
class GitUp
|
5
5
|
def run
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
branches.sort_by! do |b|
|
12
|
-
case b.name.downcase
|
13
|
-
when 'master', 'oldest'; "__#{b.name.downcase}"
|
14
|
-
when /\//; "_#{b.name.downcase}"
|
15
|
-
else; b.name.downcase
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
branches.each do |branch|
|
20
|
-
remote = remote_map[branch.name]
|
21
|
-
|
22
|
-
print branch.name.ljust(col_width)
|
23
|
-
|
24
|
-
if remote.commit.sha == branch.commit.sha
|
25
|
-
puts "up to date".green
|
26
|
-
next
|
27
|
-
end
|
28
|
-
|
29
|
-
base = merge_base(branch.name, remote.name)
|
30
|
-
|
31
|
-
if base == remote.commit.sha
|
32
|
-
puts "ahead of upstream".blue
|
33
|
-
next
|
34
|
-
end
|
6
|
+
command = ['git', 'fetch', '--multiple']
|
7
|
+
command << '--prune' if prune?
|
8
|
+
command << '--all' if config("fetch.all")
|
9
|
+
command += remotes
|
35
10
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
else
|
41
|
-
puts "diverged".red
|
42
|
-
next
|
43
|
-
end
|
11
|
+
# puts command.join(" ") # TODO: implement a 'debug' config option
|
12
|
+
system(*command)
|
13
|
+
raise GitError, "`git fetch` failed" unless $? == 0
|
14
|
+
@remote_map = nil # flush cache after fetch
|
44
15
|
|
45
|
-
|
46
|
-
|
47
|
-
|
16
|
+
Grit::Git.with_timeout(0) do
|
17
|
+
with_stash do
|
18
|
+
returning_to_current_branch do
|
19
|
+
rebase_all_branches
|
48
20
|
end
|
49
21
|
end
|
50
22
|
end
|
@@ -55,15 +27,61 @@ class GitUp
|
|
55
27
|
exit 1
|
56
28
|
end
|
57
29
|
|
30
|
+
def rebase_all_branches
|
31
|
+
col_width = branches.map { |b| b.name.length }.max + 1
|
32
|
+
|
33
|
+
if config("case-insensitive")
|
34
|
+
branches.sort_by! do |b|
|
35
|
+
case b.name.downcase
|
36
|
+
when 'master', 'oldest'; "__#{b.name.downcase}"
|
37
|
+
when /\//; "_#{b.name.downcase}"
|
38
|
+
else; b.name.downcase
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
branches.each do |branch|
|
44
|
+
remote = remote_map[branch.name]
|
45
|
+
|
46
|
+
print branch.name.ljust(col_width)
|
47
|
+
|
48
|
+
if remote.commit.sha == branch.commit.sha
|
49
|
+
puts "up to date".green
|
50
|
+
next
|
51
|
+
end
|
52
|
+
|
53
|
+
base = merge_base(branch.name, remote.name)
|
54
|
+
|
55
|
+
if base == remote.commit.sha
|
56
|
+
puts "ahead of upstream".blue
|
57
|
+
next
|
58
|
+
end
|
59
|
+
|
60
|
+
if base == branch.commit.sha
|
61
|
+
puts "fast-forwarding...".yellow
|
62
|
+
elsif config("auto-rebase")
|
63
|
+
puts "rebasing...".yellow
|
64
|
+
else
|
65
|
+
puts "diverged".red
|
66
|
+
next
|
67
|
+
end
|
68
|
+
|
69
|
+
log(branch, remote)
|
70
|
+
checkout(branch.name)
|
71
|
+
rebase(remote)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
58
75
|
def repo
|
59
76
|
@repo ||= get_repo
|
60
77
|
end
|
61
78
|
|
62
79
|
def get_repo
|
63
|
-
|
80
|
+
repo_dir = `git rev-parse --show-toplevel`.chomp
|
64
81
|
|
65
82
|
if $? == 0
|
66
|
-
|
83
|
+
Dir.chdir repo_dir
|
84
|
+
@repo = Grit::Repo.new(repo_dir)
|
67
85
|
else
|
68
86
|
raise GitError, "We don't seem to be in a git repository."
|
69
87
|
end
|
@@ -94,21 +112,9 @@ class GitUp
|
|
94
112
|
repo.remotes.find { |r| r.name == "#{remote_name}/#{remote_branch}" }
|
95
113
|
end
|
96
114
|
|
97
|
-
def fetch_remotes
|
98
|
-
args =
|
99
|
-
(config("prune") ? ['--prune'] : []) +
|
100
|
-
(config("fetch-all") ? ['--all'] : ['--multiple', *remotes])
|
101
|
-
system('git', 'fetch', *args)
|
102
|
-
raise GitError, "`git fetch` failed" unless $? == 0
|
103
|
-
@remote_map = nil # flush cache after fetch
|
104
|
-
end
|
105
|
-
|
106
115
|
def with_stash
|
107
116
|
stashed = false
|
108
117
|
|
109
|
-
status = repo.status
|
110
|
-
change_count = status.added.length + status.changed.length + status.deleted.length
|
111
|
-
|
112
118
|
if change_count > 0
|
113
119
|
puts "stashing #{change_count} changes".magenta
|
114
120
|
repo.git.stash
|
@@ -241,8 +247,48 @@ EOS
|
|
241
247
|
config("bundler.check") == 'true' || ENV['GIT_UP_BUNDLER_CHECK'] == 'true'
|
242
248
|
end
|
243
249
|
|
250
|
+
def prune?
|
251
|
+
required_version = "1.6.6"
|
252
|
+
config_value = config("fetch.prune")
|
253
|
+
|
254
|
+
if git_version_at_least?(required_version)
|
255
|
+
config_value != 'false'
|
256
|
+
else
|
257
|
+
if config_value == 'true'
|
258
|
+
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
|
259
|
+
end
|
260
|
+
|
261
|
+
false
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
265
|
+
def change_count
|
266
|
+
@change_count ||= begin
|
267
|
+
diff_status = repo.status
|
268
|
+
actual_status = repo.git.status(:porcelain => true).split("\n").map {|l| l[3..-1]}
|
269
|
+
|
270
|
+
added = diff_status.added.select { |(x,y)| actual_status.include? x }
|
271
|
+
changed = diff_status.changed.select { |(x,y)| actual_status.include? x }
|
272
|
+
deleted = diff_status.deleted.select { |(x,y)| actual_status.include? x }
|
273
|
+
|
274
|
+
added.length + changed.length + deleted.length
|
275
|
+
end
|
276
|
+
end
|
277
|
+
|
244
278
|
def config(key)
|
245
279
|
repo.config["git-up.#{key}"]
|
246
280
|
end
|
281
|
+
|
282
|
+
def git_version_at_least?(required_version)
|
283
|
+
(version_array(git_version) <=> version_array(required_version)) >= 0
|
284
|
+
end
|
285
|
+
|
286
|
+
def version_array(version_string)
|
287
|
+
version_string.split('.').map { |s| s.to_i }
|
288
|
+
end
|
289
|
+
|
290
|
+
def git_version
|
291
|
+
`git --version`[/\d+(\.\d+)+/]
|
292
|
+
end
|
247
293
|
end
|
248
294
|
|
data/lib/git-up/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: git-up-decklin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.5.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,11 +13,11 @@ authors:
|
|
13
13
|
autorequire:
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
|
-
date:
|
16
|
+
date: 2012-09-10 00:00:00.000000000 Z
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
19
19
|
name: thoughtbot-shoulda
|
20
|
-
requirement:
|
20
|
+
requirement: !ruby/object:Gem::Requirement
|
21
21
|
none: false
|
22
22
|
requirements:
|
23
23
|
- - ! '>='
|
@@ -25,10 +25,15 @@ dependencies:
|
|
25
25
|
version: '0'
|
26
26
|
type: :development
|
27
27
|
prerelease: false
|
28
|
-
version_requirements:
|
28
|
+
version_requirements: !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
29
34
|
- !ruby/object:Gem::Dependency
|
30
35
|
name: colored
|
31
|
-
requirement:
|
36
|
+
requirement: !ruby/object:Gem::Requirement
|
32
37
|
none: false
|
33
38
|
requirements:
|
34
39
|
- - ! '>='
|
@@ -36,10 +41,15 @@ dependencies:
|
|
36
41
|
version: '1.2'
|
37
42
|
type: :runtime
|
38
43
|
prerelease: false
|
39
|
-
version_requirements:
|
44
|
+
version_requirements: !ruby/object:Gem::Requirement
|
45
|
+
none: false
|
46
|
+
requirements:
|
47
|
+
- - ! '>='
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '1.2'
|
40
50
|
- !ruby/object:Gem::Dependency
|
41
51
|
name: grit
|
42
|
-
requirement:
|
52
|
+
requirement: !ruby/object:Gem::Requirement
|
43
53
|
none: false
|
44
54
|
requirements:
|
45
55
|
- - ! '>='
|
@@ -47,7 +57,12 @@ dependencies:
|
|
47
57
|
version: '0'
|
48
58
|
type: :runtime
|
49
59
|
prerelease: false
|
50
|
-
version_requirements:
|
60
|
+
version_requirements: !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
51
66
|
description:
|
52
67
|
email:
|
53
68
|
- aanand.prasad@gmail.com
|
@@ -83,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
83
98
|
version: '0'
|
84
99
|
requirements: []
|
85
100
|
rubyforge_project:
|
86
|
-
rubygems_version: 1.8.
|
101
|
+
rubygems_version: 1.8.23
|
87
102
|
signing_key:
|
88
103
|
specification_version: 3
|
89
104
|
summary: git command to fetch and rebase all branches
|