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