aharrison24-git-external 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/git-external +47 -1
- metadata +2 -2
data/bin/git-external
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# encoding: utf-8
|
2
3
|
|
3
4
|
$root_dir = `git rev-parse --show-toplevel`.chomp
|
4
5
|
$externals_file = "#{$root_dir}/.gitexternals"
|
@@ -7,10 +8,13 @@ $configurations = {}
|
|
7
8
|
|
8
9
|
def usage
|
9
10
|
puts "Usage: git external add <repository-url> <path> [<branch>]"
|
11
|
+
puts " or: git external rm <path>"
|
12
|
+
puts " or: git external status"
|
10
13
|
puts " or: git external init [--] [<path>...]"
|
11
14
|
puts " or: git external update [--] [<path>...]"
|
12
15
|
puts " or: git external cmd '<command>'"
|
13
16
|
puts " or: git external list"
|
17
|
+
puts " or: git external heads"
|
14
18
|
end
|
15
19
|
|
16
20
|
def load_configuration
|
@@ -18,7 +22,7 @@ def load_configuration
|
|
18
22
|
lines = `git config -l -f #{$externals_file}`.split(/\n/)
|
19
23
|
$configurations = {}
|
20
24
|
lines.each do |line|
|
21
|
-
if line =~ /^external\.([
|
25
|
+
if line =~ /^external\.([^$]+)\.([^=]+)=(.*)$/
|
22
26
|
$configurations[$1.chomp] ||= {}
|
23
27
|
$configurations[$1.chomp][$2.chomp] = $3.chomp
|
24
28
|
end
|
@@ -101,6 +105,47 @@ def get_default_head(path)
|
|
101
105
|
end
|
102
106
|
end
|
103
107
|
|
108
|
+
def execute(cmd)
|
109
|
+
values = []
|
110
|
+
IO.popen(cmd) do |f|
|
111
|
+
tmp = f.gets
|
112
|
+
values.push(tmp.gsub(/\r/, '').gsub(/\n/, '')) unless tmp.nil?
|
113
|
+
end
|
114
|
+
return $?.exitstatus, values
|
115
|
+
end
|
116
|
+
|
117
|
+
def command_status
|
118
|
+
ok = 0
|
119
|
+
broken = 0
|
120
|
+
$configurations.each do |name, config|
|
121
|
+
branch = config["branch"]
|
122
|
+
url = config["url"]
|
123
|
+
path = config["path"]
|
124
|
+
|
125
|
+
gitBranchExit, gitBranch = execute("cd #{path} && git config \"branch.$(git symbolic-ref HEAD --short).merge\" | sed \"s/refs\\/heads\\///g\"")
|
126
|
+
gitRemoteExit, gitRemote = execute("cd #{path} && git config \"remote.$(git config \"branch.$(git symbolic-ref HEAD --short).remote\").url\"");
|
127
|
+
|
128
|
+
if gitBranchExit != 0 && gitRemoteExit != 0
|
129
|
+
puts " ✗ #{path}: exit code #{gitBranchExit}, #{gitRemoteExit}"
|
130
|
+
broken += 1
|
131
|
+
else
|
132
|
+
if branch == gitBranch[0]
|
133
|
+
if url == gitRemote[0]
|
134
|
+
puts " ✓ #{path}"
|
135
|
+
ok += 1
|
136
|
+
else
|
137
|
+
puts " ✗ #{path} -- expected url '#{url}' but was '#{gitRemote[0]}'"
|
138
|
+
broken +=1
|
139
|
+
end
|
140
|
+
else
|
141
|
+
puts " ✗ #{path} -- expected branch '#{branch}' but was '#{gitBranch[0]}'"
|
142
|
+
broken +=1
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
puts "#{broken > 0 ? "✗" : "✓"} » #{ok} ok • #{broken} broken"
|
147
|
+
end
|
148
|
+
|
104
149
|
def command_add(url, path, branch='master')
|
105
150
|
command_rm(path)
|
106
151
|
`git config -f #{$externals_file} --add external.#{path}.path #{path}`
|
@@ -158,6 +203,7 @@ load_configuration
|
|
158
203
|
command=ARGV[0]
|
159
204
|
|
160
205
|
case command
|
206
|
+
when "status" then command_status
|
161
207
|
when "add" then command_add ARGV[1], ARGV[2], ARGV[3] || "master"
|
162
208
|
when "rm" then command_rm ARGV[1]
|
163
209
|
when "init" then command_init
|
metadata
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aharrison24-git-external
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
|
-
- Daniel Cestari, Alastair Harrison
|
8
|
+
- Daniel Cestari, Olivier Bazoud, Alastair Harrison
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|