aharrison24-git-external 0.1.7 → 0.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/bin/git-external +127 -48
- metadata +9 -12
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6ad49e8845d92de9d47be9d74d95f5ff9d37b492
|
4
|
+
data.tar.gz: 6ae2f7a8d640d61994029016e7348cfe37c8f054
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cab8233555c89431b4d4f2ca37c3bf65976db34e039ec2270ab6d15f719079f9f95930bf41878e80f682732094f92c842a76bf338f0b5474b3c64d965dc9bac4
|
7
|
+
data.tar.gz: 961c736c0c8c7bb4aba7b5a9f43e0a7d6f2577f9729508a971a874a67829b09de17c4e3b8423539e29a8e4c5aa4e6b6ed53e069e556a066e00e0978d987890bd
|
data/bin/git-external
CHANGED
@@ -10,8 +10,9 @@ def usage
|
|
10
10
|
puts "Usage: git external add <repository-url> <path> [<branch>]"
|
11
11
|
puts " or: git external rm <path>"
|
12
12
|
puts " or: git external status"
|
13
|
-
puts " or: git external init
|
14
|
-
puts " or: git external
|
13
|
+
puts " or: git external init"
|
14
|
+
puts " or: git external init_single <name>"
|
15
|
+
puts " or: git external update"
|
15
16
|
puts " or: git external cmd '<command>'"
|
16
17
|
puts " or: git external list"
|
17
18
|
puts " or: git external heads"
|
@@ -32,7 +33,7 @@ end
|
|
32
33
|
|
33
34
|
def print_configuration
|
34
35
|
$configurations.each do |name, config|
|
35
|
-
puts name
|
36
|
+
puts "* #{name}"
|
36
37
|
config.each do |key, value|
|
37
38
|
puts "\t#{key}: #{value}"
|
38
39
|
end
|
@@ -66,6 +67,30 @@ def uncommitted_changes?(path)
|
|
66
67
|
return ((diffExit == 1) ? true : false)
|
67
68
|
end
|
68
69
|
|
70
|
+
# Check for untracked files
|
71
|
+
def untracked_files?(path)
|
72
|
+
untrackedExit, untracked = execute("cd #{path}; git ls-files --others --exclude-standard")
|
73
|
+
return ((untrackedExit == 1 || untracked.length > 0) ? true : false)
|
74
|
+
end
|
75
|
+
|
76
|
+
# find how many commits we are ahead/behind our upstream
|
77
|
+
def ahead_behind_upstream(path, branch)
|
78
|
+
upstreamExit, upstream = execute("cd #{path}; git rev-list --count --left-right origin/#{branch}...#{branch} 2> /dev/null")
|
79
|
+
return "" if upstreamExit != 0
|
80
|
+
behind, ahead = upstream.first.match(/^(\d*)\t(\d*)$/).captures
|
81
|
+
my_str = ""
|
82
|
+
if Integer(behind) > 0 || Integer(ahead) > 0
|
83
|
+
my_str << "("
|
84
|
+
my_str << "Ahead by #{ahead} commit" if Integer(ahead) == 1
|
85
|
+
my_str << "Ahead by #{ahead} commits" if Integer(ahead) > 1
|
86
|
+
my_str << ", " if Integer(ahead) > 0 && Integer(behind) > 0
|
87
|
+
my_str << "Behind by #{behind} commit" if Integer(behind) == 1
|
88
|
+
my_str << "Behind by #{behind} commits" if Integer(behind) > 1
|
89
|
+
my_str << ")"
|
90
|
+
end
|
91
|
+
my_str
|
92
|
+
end
|
93
|
+
|
69
94
|
# Check if a branch exists
|
70
95
|
def branch_exists(path, branch)
|
71
96
|
branches = `cd #{path}; git branch`
|
@@ -74,40 +99,55 @@ def branch_exists(path, branch)
|
|
74
99
|
return result
|
75
100
|
end
|
76
101
|
|
77
|
-
|
102
|
+
# Check that a git repo exists in the given path
|
103
|
+
def repo_exists(path)
|
78
104
|
require 'fileutils'
|
79
|
-
|
80
|
-
|
81
|
-
else
|
82
|
-
FileUtils.makedirs File.dirname(path)
|
83
|
-
url = normalize_url url
|
84
|
-
system "git clone #{url} #{path}"
|
105
|
+
return File.directory? "#{path}/.git"
|
106
|
+
end
|
85
107
|
|
108
|
+
def update_repo(path, branch='master')
|
86
109
|
# Create a local tracking branch if it doesn't exist already
|
87
110
|
unless branch_exists(path, branch)
|
88
111
|
puts "- Creating local tracking branch: #{branch} -> origin/#{branch}"
|
89
|
-
system "cd #{path}; git branch
|
112
|
+
system "cd #{path}; git branch #{branch} --track origin/#{branch}"
|
90
113
|
end
|
91
114
|
|
92
115
|
# Check out the local branch
|
93
116
|
puts "- Checkout local branch: #{branch}"
|
94
|
-
system "cd #{path}; git checkout #{branch}"
|
117
|
+
system "cd #{path}; git checkout #{branch}; git pull;"
|
118
|
+
end
|
119
|
+
|
120
|
+
def init_external(url, path, branch='master')
|
121
|
+
require 'fileutils'
|
122
|
+
if repo_exists(path)
|
123
|
+
puts "\t- Repository already exists"
|
124
|
+
else
|
125
|
+
FileUtils.makedirs File.dirname(path)
|
126
|
+
url = normalize_url url
|
127
|
+
system "git clone #{url} #{path}"
|
128
|
+
update_repo(path, branch)
|
95
129
|
end
|
96
130
|
end
|
97
131
|
|
98
132
|
def update_external(url, path, branch='master')
|
99
|
-
|
100
|
-
|
101
|
-
|
133
|
+
if repo_exists(path)
|
134
|
+
puts "- Updating #{path}"
|
135
|
+
if uncommitted_changes?(path)
|
136
|
+
puts "#{path} - uncommitted changes detected, can not update repository"
|
137
|
+
else
|
138
|
+
update_repo(path, branch)
|
139
|
+
end
|
102
140
|
end
|
103
141
|
end
|
104
142
|
|
105
143
|
def get_default_head(path)
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
144
|
+
if repo_exists(path)
|
145
|
+
origin_head = `cd #{path}; git symbolic-ref refs/remotes/origin/HEAD`
|
146
|
+
if origin_head =~ /refs\/remotes\/origin\/(.*)/
|
147
|
+
$1
|
148
|
+
else
|
149
|
+
raise "#{path}: Can't determine default HEAD for origin remote"
|
150
|
+
end
|
111
151
|
end
|
112
152
|
end
|
113
153
|
|
@@ -123,44 +163,63 @@ end
|
|
123
163
|
def command_status
|
124
164
|
ok = 0
|
125
165
|
broken = 0
|
166
|
+
uninitialised = 0
|
167
|
+
puts "=================================================="
|
168
|
+
puts "Status:"
|
169
|
+
puts "=================================================="
|
126
170
|
$configurations.each do |name, config|
|
127
171
|
branch = config["branch"]
|
128
172
|
url = config["url"]
|
129
173
|
path = config["path"]
|
130
174
|
|
131
|
-
|
132
|
-
# This is equivalent to 'git symbolic-ref --short HEAD'
|
133
|
-
# but the --short is only available in pretty recent versions of git
|
134
|
-
headBranch = `cd #{path} && git symbolic-ref HEAD | sed \"s/refs\\/heads\\///g\"`.chomp
|
135
|
-
|
136
|
-
gitBranchExit, gitBranch = execute("cd #{path} && git config \"branch.#{headBranch}.merge\" | sed \"s/refs\\/heads\\///g\"")
|
137
|
-
gitRemoteExit, gitRemote = execute("cd #{path} && git config \"remote.$(git config \"branch.#{headBranch}.remote\").url\"");
|
175
|
+
if repo_exists(path)
|
138
176
|
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
177
|
+
# Figure out the short name of the current branch
|
178
|
+
# This is equivalent to 'git symbolic-ref --short HEAD'
|
179
|
+
# but the --short is only available in pretty recent versions of git
|
180
|
+
headBranch = `cd #{path} && git symbolic-ref HEAD | sed \"s/refs\\/heads\\///g\"`.chomp
|
181
|
+
|
182
|
+
gitBranchExit, gitBranch = execute("cd #{path} && git config \"branch.#{headBranch}.merge\" | sed \"s/refs\\/heads\\///g\"")
|
183
|
+
gitRemoteExit, gitRemote = execute("cd #{path} && git config \"remote.$(git config \"branch.#{headBranch}.remote\").url\"");
|
144
184
|
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
185
|
+
if uncommitted_changes?(path)
|
186
|
+
changesString = "(Uncommitted Changes) "
|
187
|
+
else
|
188
|
+
changesString = ""
|
189
|
+
end
|
190
|
+
|
191
|
+
if untracked_files?(path)
|
192
|
+
untrackedString = "(Untracked Files) "
|
193
|
+
else
|
194
|
+
untrackedString = ""
|
195
|
+
end
|
196
|
+
|
197
|
+
upstream = ahead_behind_upstream(path, branch)
|
198
|
+
|
199
|
+
if gitBranchExit != 0 && gitRemoteExit != 0
|
200
|
+
puts " ✗ #{path}: exit code #{gitBranchExit}, #{gitRemoteExit}"
|
201
|
+
broken += 1
|
202
|
+
else
|
203
|
+
if branch == gitBranch[0]
|
204
|
+
if url == gitRemote[0]
|
205
|
+
puts " ✓ #{path} #{upstream} #{changesString} #{untrackedString}"
|
206
|
+
ok += 1
|
207
|
+
else
|
208
|
+
puts " ✗ #{path} #{upstream} #{changesString} #{untrackedString} -- expected url '#{url}' but was '#{gitRemote[0]}'"
|
209
|
+
broken +=1
|
210
|
+
end
|
153
211
|
else
|
154
|
-
puts " ✗ #{path} #{changesString}-- expected
|
212
|
+
puts " ✗ #{path} #{changesString} #{untrackedString} -- expected branch '#{branch}' but was '#{gitBranch[0]}'"
|
155
213
|
broken +=1
|
156
214
|
end
|
157
|
-
else
|
158
|
-
puts " ✗ #{path} #{changesString}-- expected branch '#{branch}' but was '#{gitBranch[0]}'"
|
159
|
-
broken +=1
|
160
215
|
end
|
216
|
+
else
|
217
|
+
puts " ~ #{path} is not initialised"
|
218
|
+
uninitialised +=1
|
161
219
|
end
|
162
220
|
end
|
163
|
-
puts "#{broken > 0 ? "✗" : "✓"} » #{ok} ok • #{broken} broken"
|
221
|
+
puts "#{broken > 0 ? "✗" : "✓"} » #{ok} ok • #{broken} broken - #{uninitialised} uninitialised "
|
222
|
+
puts "=================================================="
|
164
223
|
end
|
165
224
|
|
166
225
|
def command_add(url, path, branch='master')
|
@@ -187,7 +246,9 @@ end
|
|
187
246
|
|
188
247
|
def command_list_default_heads
|
189
248
|
$configurations.each do |name, config|
|
190
|
-
|
249
|
+
if repo_exists(config["path"])
|
250
|
+
puts "#{name}: #{get_default_head(config["path"])}"
|
251
|
+
end
|
191
252
|
end
|
192
253
|
end
|
193
254
|
|
@@ -195,19 +256,36 @@ def command_init
|
|
195
256
|
$configurations.each do |name, config|
|
196
257
|
puts name
|
197
258
|
init_external config["url"], config["path"], config["branch"]
|
259
|
+
puts "=================================================="
|
260
|
+
end
|
261
|
+
end
|
262
|
+
|
263
|
+
def command_init_single(external_name)
|
264
|
+
$configurations.each do |name, config|
|
265
|
+
if name == external_name
|
266
|
+
puts name
|
267
|
+
init_external config["url"], config["path"], config["branch"]
|
268
|
+
end
|
198
269
|
end
|
199
270
|
end
|
200
271
|
|
201
272
|
def command_update
|
202
273
|
$configurations.each do |name, config|
|
203
|
-
|
274
|
+
if repo_exists(config["path"])
|
275
|
+
puts "=================================================="
|
276
|
+
update_external config["url"], config["path"], config["branch"]
|
277
|
+
end
|
204
278
|
end
|
279
|
+
command_status
|
205
280
|
end
|
206
281
|
|
207
282
|
def command_cmd(cmd)
|
208
283
|
$configurations.each do |name, config|
|
209
284
|
path = config['path']
|
210
|
-
|
285
|
+
if repo_exists(path)
|
286
|
+
system("echo #{path}; cd #{path}; #{cmd}")
|
287
|
+
puts "=================================================="
|
288
|
+
end
|
211
289
|
end
|
212
290
|
end
|
213
291
|
|
@@ -228,6 +306,7 @@ when "update" then command_update
|
|
228
306
|
when "cmd" then command_cmd ARGV[1]
|
229
307
|
when "list" then command_list
|
230
308
|
when "heads" then command_list_default_heads
|
309
|
+
when "init_single" then command_init_single ARGV[1]
|
231
310
|
else usage
|
232
311
|
end
|
233
312
|
|
metadata
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aharrison24-git-external
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
5
|
-
prerelease:
|
4
|
+
version: 0.1.9
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
|
-
- Daniel Cestari, Olivier Bazoud, Alastair Harrison
|
7
|
+
- Daniel Cestari, Olivier Bazoud, Alastair Harrison, Stephen Kyberd
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2016-09-20 00:00:00.000000000 Z
|
13
12
|
dependencies: []
|
14
13
|
description: Extension for git which adds a command providing similar functionality
|
15
14
|
to git submodules but without attaching each module to a single version
|
@@ -20,30 +19,28 @@ executables:
|
|
20
19
|
extensions: []
|
21
20
|
extra_rdoc_files: []
|
22
21
|
files:
|
23
|
-
-
|
24
|
-
YmluL2dpdC1leHRlcm5hbA==
|
22
|
+
- bin/git-external
|
25
23
|
homepage: http://github.com/aharrison24/git-external
|
26
24
|
licenses: []
|
25
|
+
metadata: {}
|
27
26
|
post_install_message:
|
28
27
|
rdoc_options: []
|
29
28
|
require_paths:
|
30
29
|
- lib
|
31
30
|
required_ruby_version: !ruby/object:Gem::Requirement
|
32
|
-
none: false
|
33
31
|
requirements:
|
34
|
-
- -
|
32
|
+
- - ">="
|
35
33
|
- !ruby/object:Gem::Version
|
36
34
|
version: '0'
|
37
35
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
38
|
-
none: false
|
39
36
|
requirements:
|
40
|
-
- -
|
37
|
+
- - ">="
|
41
38
|
- !ruby/object:Gem::Version
|
42
39
|
version: '0'
|
43
40
|
requirements: []
|
44
41
|
rubyforge_project:
|
45
|
-
rubygems_version:
|
42
|
+
rubygems_version: 2.5.1
|
46
43
|
signing_key:
|
47
|
-
specification_version:
|
44
|
+
specification_version: 4
|
48
45
|
summary: Git version of an svn:external, an alternative to Git Submodule
|
49
46
|
test_files: []
|