aharrison24-git-external 0.1.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.
Files changed (2) hide show
  1. data/bin/git-external +117 -0
  2. metadata +49 -0
data/bin/git-external ADDED
@@ -0,0 +1,117 @@
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
+ puts " or: git external list"
13
+ end
14
+
15
+ def load_configuration
16
+ if File.file? $externals_file
17
+ lines = `git config -l -f #{$externals_file}`.split(/\n/)
18
+ $configurations = {}
19
+ lines.each do |line|
20
+ if line =~ /^external\.([^\.]+)\.([^=]+)=(.*)$/
21
+ $configurations[$1.chomp] ||= {}
22
+ $configurations[$1.chomp][$2.chomp] = $3.chomp
23
+ end
24
+ end
25
+ end
26
+ end
27
+
28
+ def print_configuration
29
+ $configurations.each do |name, config|
30
+ puts name
31
+ config.each do |key, value|
32
+ puts "\t#{key}: #{value}"
33
+ end
34
+ end
35
+ end
36
+
37
+ def normalize_url(url)
38
+ if url =~ /^\./
39
+ origin_url = `git config --get remote.origin.url`.chomp
40
+
41
+ unless origin_url =~ /^\w+:\/\//
42
+ if origin_url =~ /^([^:\/]+):([^:]+)/
43
+ origin_url = "ssh://#{$1}/#{$2}"
44
+ end
45
+ end
46
+
47
+ require 'uri'
48
+ uri = URI.parse URI.encode origin_url
49
+ uri.path = File.expand_path(url, uri.path)
50
+ uri.to_s
51
+ else
52
+ url
53
+ end
54
+ end
55
+
56
+ def init_external(url, path)
57
+ require 'fileutils'
58
+ unless File.directory? "#{path}/.git"
59
+ FileUtils.makedirs File.dirname(path)
60
+ url = normalize_url url
61
+ system "git clone #{url} #{path}"
62
+ end
63
+ end
64
+
65
+ def update_external(url, path)
66
+ require 'fileutils'
67
+ if File.directory? "#{path}/.git"
68
+ `cd #{path}; git pull origin master`
69
+ end
70
+ end
71
+
72
+ def command_add(url, path)
73
+ `git config -f #{$externals_file} --add external.#{path}.path #{path}`
74
+ `git config -f #{$externals_file} --add external.#{path}.url #{url}`
75
+ `echo "#{path}" >> #{$ignore_file}`
76
+ end
77
+
78
+ def command_rm(path)
79
+ `git config -f #{$externals_file} --unset external.#{path}.path`
80
+ `git config -f #{$externals_file} --unset external.#{path}.url`
81
+ `git config -f #{$externals_file} --remove-section external.#{path}`
82
+
83
+ # Remove entry from .gitignore file
84
+ `perl -pi -e 's/\\Q#{path.gsub(/\//, '\/')}\\E\n//g' #{$ignore_file}`
85
+ File.delete $externals_file if `wc -l #{$externals_file}`.chomp.to_i == 0
86
+ end
87
+
88
+ def command_init
89
+ $configurations.each do |name, config|
90
+ puts name
91
+ init_external config["url"], config["path"]
92
+ end
93
+ end
94
+
95
+ def command_update
96
+ $configurations.each do |name, config|
97
+ update_external config["url"], config["path"]
98
+ end
99
+ end
100
+
101
+ def command_list
102
+ print_configuration
103
+ end
104
+
105
+ load_configuration
106
+
107
+ command=ARGV[0]
108
+
109
+ case command
110
+ when "add" then command_add ARGV[1], ARGV[2]
111
+ when "rm" then command_rm ARGV[1]
112
+ when "init" then command_init
113
+ when "update" then command_update
114
+ when "list" then command_list
115
+ else usage
116
+ end
117
+
metadata ADDED
@@ -0,0 +1,49 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: aharrison24-git-external
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Daniel Cestari
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-05-01 00:00:00.000000000 Z
13
+ dependencies: []
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:
17
+ - dcestari@gmail.com
18
+ executables:
19
+ - git-external
20
+ extensions: []
21
+ extra_rdoc_files: []
22
+ files:
23
+ - !binary |-
24
+ YmluL2dpdC1leHRlcm5hbA==
25
+ homepage: http://github.com/dcestari/git-external
26
+ licenses: []
27
+ post_install_message:
28
+ rdoc_options: []
29
+ require_paths:
30
+ - lib
31
+ required_ruby_version: !ruby/object:Gem::Requirement
32
+ none: false
33
+ requirements:
34
+ - - ! '>='
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
37
+ required_rubygems_version: !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ! '>='
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ requirements: []
44
+ rubyforge_project:
45
+ rubygems_version: 1.8.11
46
+ signing_key:
47
+ specification_version: 3
48
+ summary: Git version of an svn:external, an alternative to Git Submodule
49
+ test_files: []