git-external 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/git-external +9 -100
- data/lib/git_external.rb +116 -0
- metadata +25 -43
data/bin/git-external
CHANGED
@@ -1,109 +1,18 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
|
4
|
-
$externals_file = "#{$root_dir}/.gitexternals"
|
5
|
-
$ignore_file = "#{$root_dir}/.gitignore"
|
6
|
-
$configurations = {}
|
3
|
+
require 'git_external'
|
7
4
|
|
8
|
-
|
9
|
-
|
10
|
-
puts " or: git external init [--] [<path>...]"
|
11
|
-
puts " or: git external update [--] [<path>...]"
|
12
|
-
end
|
13
|
-
|
14
|
-
def load_configuration
|
15
|
-
if File.file? $externals_file
|
16
|
-
lines = `git config -l -f #{$externals_file}`.split(/\n/)
|
17
|
-
$configurations = {}
|
18
|
-
lines.each do |line|
|
19
|
-
if line =~ /^external\.([^\.]+)\.([^=]+)=(.*)$/
|
20
|
-
$configurations[$1.chomp] ||= {}
|
21
|
-
$configurations[$1.chomp][$2.chomp] = $3.chomp
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def print_configuration
|
28
|
-
$configurations.each do |name, config|
|
29
|
-
puts name
|
30
|
-
config.each do |key, value|
|
31
|
-
puts "\t#{key}: #{value}"
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def normalize_url(url)
|
37
|
-
if url =~ /^\./
|
38
|
-
origin_url = `git config --get remote.origin.url`.chomp
|
39
|
-
|
40
|
-
unless origin_url =~ /^\w+:\/\//
|
41
|
-
if origin_url =~ /^([^:\/]+):([^:]+)/
|
42
|
-
origin_url = "ssh://#{$1}/#{$2}"
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
require 'uri'
|
47
|
-
uri = URI.parse URI.encode origin_url
|
48
|
-
uri.path = File.expand_path(url, uri.path)
|
49
|
-
uri.to_s
|
50
|
-
else
|
51
|
-
url
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
def init_external(url, path)
|
56
|
-
require 'ftools'
|
57
|
-
unless File.directory? "#{path}/.git"
|
58
|
-
File.makedirs File.dirname(path)
|
59
|
-
url = normalize_url url
|
60
|
-
system "git clone #{url} #{path}"
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
def update_external(url, path)
|
65
|
-
require 'ftools'
|
66
|
-
if File.directory? "#{path}/.git"
|
67
|
-
`cd #{path}; git pull origin master`
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
def command_add(url, path)
|
72
|
-
`git config -f #{$externals_file} --add external.#{path}.path #{path}`
|
73
|
-
`git config -f #{$externals_file} --add external.#{path}.url #{url}`
|
74
|
-
`echo "#{path}" >> #{$ignore_file}`
|
75
|
-
end
|
76
|
-
|
77
|
-
def command_rm(path)
|
78
|
-
`git config -f #{$externals_file} --unset external.#{path}.path`
|
79
|
-
`git config -f #{$externals_file} --unset external.#{path}.url`
|
80
|
-
`git config -f #{$externals_file} --remove-section external.#{path}`
|
81
|
-
`perl -pi -e 's/\\Q#{path.gsub(/\//, '\/')}\\E\n//g' #{$ignore_file}`
|
82
|
-
File.delete $externals_file if `wc -l #{$externals_file}`.chomp.to_i == 0
|
83
|
-
end
|
84
|
-
|
85
|
-
def command_init
|
86
|
-
$configurations.each do |name, config|
|
87
|
-
puts name
|
88
|
-
init_external config["url"], config["path"]
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
def command_update
|
93
|
-
$configurations.each do |name, config|
|
94
|
-
update_external config["url"], config["path"]
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
load_configuration
|
5
|
+
git_external = GitExternal.new
|
6
|
+
git_external.load_configuration
|
99
7
|
|
100
8
|
command=ARGV[0]
|
101
9
|
|
102
10
|
case command
|
103
|
-
when "add"
|
104
|
-
when "rm"
|
105
|
-
when "init"
|
106
|
-
when "update" then command_update
|
107
|
-
|
11
|
+
when "add" then git_external.command_add ARGV[1], ARGV[2], ARGV[3] || "master"
|
12
|
+
when "rm" then git_external.command_rm ARGV[1]
|
13
|
+
when "init" then git_external.command_init
|
14
|
+
when "update" then git_external.command_update
|
15
|
+
when "cmd" then git_external.command_cmd ARGV[1]
|
16
|
+
else git_external.usage
|
108
17
|
end
|
109
18
|
|
data/lib/git_external.rb
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
class GitExternal
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@root_dir = `git rev-parse --show-toplevel`.chomp
|
7
|
+
@externals_file = "#{@root_dir}/.gitexternals"
|
8
|
+
@ignore_file = "#{@root_dir}/.gitignore"
|
9
|
+
@configurations = {}
|
10
|
+
end
|
11
|
+
|
12
|
+
def usage
|
13
|
+
puts "Usage: git external add <repository-url> <path> [<branch>]"
|
14
|
+
puts " or: git external init [--] [<path>...]"
|
15
|
+
puts " or: git external update [--] [<path>...]"
|
16
|
+
puts " or: git external cmd '<command>'"
|
17
|
+
end
|
18
|
+
|
19
|
+
def load_configuration
|
20
|
+
if File.file? @externals_file
|
21
|
+
lines = `git config -l -f #{@externals_file}`.split(/\n/)
|
22
|
+
@configurations = parse_configuration lines
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def parse_configuration(lines)
|
27
|
+
config = {}
|
28
|
+
lines.each do |line|
|
29
|
+
if line =~ /^external\.([^\.]+)\.([^=]+)=(.*)$/
|
30
|
+
config[$1.chomp] ||= {}
|
31
|
+
config[$1.chomp][$2.chomp] = $3.chomp
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
config
|
36
|
+
end
|
37
|
+
|
38
|
+
def print_configuration
|
39
|
+
@configurations.each do |name, config|
|
40
|
+
puts name
|
41
|
+
config.each do |key, value|
|
42
|
+
puts "\t#{key}: #{value}"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def normalize_url(url)
|
48
|
+
if url =~ /^\./
|
49
|
+
origin_url = `git config --get remote.origin.url`.chomp
|
50
|
+
|
51
|
+
unless origin_url =~ /^\w+:\/\//
|
52
|
+
if origin_url =~ /^([^:\/]+):([^:]+)/
|
53
|
+
origin_url = "ssh://#{$1}/#{$2}"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
require 'uri'
|
58
|
+
uri = URI.parse URI.encode origin_url
|
59
|
+
uri.path = File.expand_path(url, uri.path)
|
60
|
+
uri.to_s
|
61
|
+
else
|
62
|
+
url
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def init_external(url, path, branch='master')
|
67
|
+
unless File.directory? "#{path}/.git"
|
68
|
+
FileUtils.makedirs File.dirname(path)
|
69
|
+
url = normalize_url url
|
70
|
+
system "git clone #{url} #{path}"
|
71
|
+
system "cd #{path}; git checkout --track -b #{branch} origin/#{branch}" unless branch == 'master'
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def update_external(url, path, branch='master')
|
76
|
+
if File.directory? "#{path}/.git"
|
77
|
+
`cd #{path}; git pull origin #{branch}`
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def command_add(url, path, branch='master')
|
82
|
+
`git config -f #{@externals_file} --add external.#{path}.path #{path}`
|
83
|
+
`git config -f #{@externals_file} --add external.#{path}.url #{url}`
|
84
|
+
`git config -f #{@externals_file} --add external.#{path}.branch #{branch}`
|
85
|
+
`echo "#{path}" >> #{@ignore_file}`
|
86
|
+
end
|
87
|
+
|
88
|
+
def command_rm(path)
|
89
|
+
`git config -f #{@externals_file} --unset external.#{path}.path`
|
90
|
+
`git config -f #{@externals_file} --unset external.#{path}.url`
|
91
|
+
`git config -f #{@externals_file} --unset external.#{path}.branch`
|
92
|
+
`git config -f #{@externals_file} --remove-section external.#{path}`
|
93
|
+
`perl -pi -e 's/\\Q#{path.gsub(/\//, '\/')}\\E\n//g' #{@ignore_file}`
|
94
|
+
File.delete @externals_file if `wc -l #{@externals_file}`.chomp.to_i == 0
|
95
|
+
end
|
96
|
+
|
97
|
+
def command_init
|
98
|
+
@configurations.each do |name, config|
|
99
|
+
puts name
|
100
|
+
init_external config["url"], config["path"], config["branch"]
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def command_update
|
105
|
+
@configurations.each do |name, config|
|
106
|
+
update_external config["url"], config["path"], config["branch"]
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
def command_cmd(cmd)
|
111
|
+
@configurations.each do |name, config|
|
112
|
+
path = config['path']
|
113
|
+
system("echo #{path}; cd #{path}; #{cmd}")
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
metadata
CHANGED
@@ -1,68 +1,50 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: git-external
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 1
|
9
|
-
- 1
|
10
|
-
version: 0.1.1
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
prerelease:
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Daniel Cestari
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
date: 2010-09-27 00:00:00 -04:30
|
19
|
-
default_executable:
|
12
|
+
date: 2012-10-28 00:00:00.000000000 Z
|
20
13
|
dependencies: []
|
21
|
-
|
22
|
-
|
23
|
-
email:
|
14
|
+
description: Extension for git which adds a command providing similar functionality
|
15
|
+
to git submodules but without attaching each module to a single version
|
16
|
+
email:
|
24
17
|
- dcestari@gmail.com
|
25
|
-
executables:
|
18
|
+
executables:
|
26
19
|
- git-external
|
27
20
|
extensions: []
|
28
|
-
|
29
21
|
extra_rdoc_files: []
|
30
|
-
|
31
|
-
|
22
|
+
files:
|
23
|
+
- lib/git_external.rb
|
32
24
|
- bin/git-external
|
33
|
-
has_rdoc: true
|
34
25
|
homepage: http://github.com/dcestari/git-external
|
35
26
|
licenses: []
|
36
|
-
|
37
27
|
post_install_message:
|
38
28
|
rdoc_options: []
|
39
|
-
|
40
|
-
require_paths:
|
29
|
+
require_paths:
|
41
30
|
- lib
|
42
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
31
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
43
32
|
none: false
|
44
|
-
requirements:
|
45
|
-
- -
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
|
48
|
-
|
49
|
-
- 0
|
50
|
-
version: "0"
|
51
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
33
|
+
requirements:
|
34
|
+
- - ! '>='
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '0'
|
37
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
38
|
none: false
|
53
|
-
requirements:
|
54
|
-
- -
|
55
|
-
- !ruby/object:Gem::Version
|
56
|
-
|
57
|
-
segments:
|
58
|
-
- 0
|
59
|
-
version: "0"
|
39
|
+
requirements:
|
40
|
+
- - ! '>='
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
60
43
|
requirements: []
|
61
|
-
|
62
44
|
rubyforge_project:
|
63
|
-
rubygems_version: 1.
|
45
|
+
rubygems_version: 1.8.23
|
64
46
|
signing_key:
|
65
47
|
specification_version: 3
|
66
48
|
summary: Git version of an svn:external, an alternative to Git Submodule
|
67
49
|
test_files: []
|
68
|
-
|
50
|
+
has_rdoc:
|