repomap 0.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/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ *.gem
2
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source "http://rubygems.org"
2
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,18 @@
1
+ Copyright (C) 2012 Gursimran Singh
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ this software and associated documentation files (the "Software"), to deal in
5
+ the Software without restriction, including without limitation the rights to
6
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7
+ the Software, and to permit persons to whom the Software is furnished to do so,
8
+ subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,65 @@
1
+ # RepoMap
2
+
3
+ Keep track of your git repos.
4
+
5
+ Want all git repos in some directory to be listed in one place?
6
+
7
+ - `repo add -r [directory holding repositories]`
8
+ - `repo ls`
9
+
10
+ Add and remove any git repository to RepoMap, and it will keep
11
+ track of them in a simple YAML file. You can also pretty print
12
+ your git repositories.
13
+
14
+ CLI:
15
+ - `repo ls`
16
+ - `repo add [-r for recursive] [git repo path]`
17
+ - `repo rm [git repo path]`
18
+
19
+ ## Installation
20
+
21
+ Things are pretty new, but since this project doesn't really do much beyond
22
+ affect the state of one file that it itself creates, it's actually OK to use
23
+ already. Check out the specs in `spec` and the source in `lib` if you wanna see
24
+ what's happening.
25
+
26
+ - `gem build repomap.gemspec`
27
+ - `gem install repomap-x.x.x.gem`
28
+
29
+ On first use, `~/.repomap.yml` will be created.
30
+
31
+ ## Usage
32
+
33
+ - `repo [global opts] [subcommand] [subcommand opts]`
34
+
35
+ - `repo -h` for help
36
+
37
+ - `repo [subcommand] -h` for help about subcommands
38
+
39
+ **Sub Commands**
40
+
41
+ - add [path to git repository]
42
+ - Add the given git repository to RepoMan
43
+ - Use `-r` switch to add all git repository under some path
44
+ - rm [path to git repository]
45
+ - Add the given git repository to RepoMan
46
+ - ls
47
+ - List all git repositories in RepoMan
48
+
49
+ ## Testing
50
+
51
+ - Run `rake` to run all specs.
52
+
53
+ ## Future
54
+
55
+ - ~~search a given path recusively for all git repos, adding any that
56
+ are found to RepoMan~~
57
+ - ~~make a gemspec~~
58
+ - add some simple specs
59
+ - added specs for `#add!`
60
+ - ~~change name because of conflicts with other gem names~~
61
+ - an 'update' command to update information about each repo that RepoMan
62
+ knows about
63
+ - keep track of other meta data about git repos (remotes, for instance)
64
+ - then you could list your github repos and their paths
65
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'rspec/core/rake_task'
2
+ require 'bundler/gem_tasks'
3
+
4
+ task :default => :spec
5
+
6
+ RSpec::Core::RakeTask.new
data/bin/repo ADDED
@@ -0,0 +1,81 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $: << "#{File.dirname(__FILE__)}/../lib"
4
+ require 'repomap'
5
+ require 'optparse'
6
+
7
+ include RepoMap
8
+
9
+ banner = "Usage: repo [global flags] [[subcommand] subcommand flags]"
10
+
11
+ global = OptionParser.new do |opts|
12
+ opts.banner = banner
13
+ opts.on( "-h", "--help", "Display this screen" ) do
14
+ STDOUT.puts opts
15
+ exit 0
16
+ end
17
+ opts.on("-v", "--version", "Display the version") do
18
+ STDOUT.puts "RepoMap #{RepoMap::VERSION}"
19
+ exit 0
20
+ end
21
+ end
22
+
23
+ add_opts = {}
24
+ add_opts[:recursive] = false
25
+ subcommands = {
26
+ 'add' => OptionParser.new do |opts|
27
+ opts.banner = "Usage: add [path to git repository]"
28
+ opts.on( "-h", "--help", "Display this screen" ) do
29
+ STDOUT.puts opts
30
+ exit 0
31
+ end
32
+ opts.on("-r", "--recursive", "Add all git repositories recursively") do
33
+ add_opts[:recursive] = true
34
+ end
35
+ end,
36
+ 'rm' => OptionParser.new do |opts|
37
+ opts.banner = "Usage: rm [path to git repository]"
38
+ opts.on( "-h", "--help", "Display this screen" ) do
39
+ STDOUT.puts opts
40
+ exit 0
41
+ end
42
+ end,
43
+ 'ls' => OptionParser.new do |opts|
44
+ opts.banner = "Usage: ls"
45
+ opts.on( "-h", "--help", "Display this screen" ) do
46
+ STDOUT.puts opts
47
+ exit 0
48
+ end
49
+ end
50
+ }
51
+
52
+ begin
53
+ global.order!
54
+
55
+ argv_minus_global_opts = ARGV.dup
56
+
57
+ subcommands[ARGV.shift].order!
58
+ subcommand = argv_minus_global_opts.shift
59
+
60
+ if ((subcommand =~ /add/)==0)
61
+ if argv_minus_global_opts.length >= 1
62
+ add_opts[:add] = argv_minus_global_opts[-1]
63
+ RepoMap.handle(add_opts)
64
+ end
65
+ end
66
+
67
+ if ((subcommand =~ /rm/)==0)
68
+ if argv_minus_global_opts.length==1
69
+ path = argv_minus_global_opts.shift
70
+ RepoMap.handle(:remove=>path)
71
+ end
72
+ end
73
+
74
+ RepoMap.handle(:list=>true) if ((subcommand =~ /ls/)==0)
75
+
76
+ exit 0
77
+ rescue OptionParser::MissingArgument => e
78
+ puts "repo: #{e}"
79
+ rescue NoMethodError => e
80
+ puts banner
81
+ end
@@ -0,0 +1,40 @@
1
+ module RepoMap
2
+
3
+ def add! path
4
+ if File.directory? path and has_git? path
5
+ full_path = File.expand_path(path)
6
+ basename = File.basename(full_path)
7
+ puts "repo: I'm adding '#{basename}' to '#{repo_map}'"
8
+ add_repo! basename, full_path
9
+ else
10
+ STDERR.puts "repo: Not a git repository -- #{path}"
11
+ exit 1
12
+ end
13
+ end
14
+
15
+ def add_recursive! path
16
+ if File.directory?(path) and has_git?(path)
17
+ add! path
18
+ elsif File.directory?(path) and !has_git?(path)
19
+ Dir.foreach(path) do |item|
20
+ next if item == '.' or item == '..'
21
+ item_path = File.join(File.expand_path(path), item)
22
+ add_recursive! item_path if File.directory? item_path
23
+ end
24
+ else
25
+ STDERR.puts "repo: Not a directory or repository -- #{path}"
26
+ exit 1
27
+ end
28
+ end
29
+
30
+ def add_repo! reponame, full_path
31
+ repo_map_validate
32
+ hash = YAML::load(File.read(repo_map))
33
+ hash = {} if hash==nil
34
+ hash[full_path.to_sym] = {:name => reponame}
35
+ File.open(repo_map, "w") do |f|
36
+ f.write hash.to_yaml
37
+ end
38
+ end
39
+
40
+ end
@@ -0,0 +1,9 @@
1
+ module RepoMap
2
+
3
+ ENV['REPO_MAP'] = "#{`echo $HOME`.chomp}/.repomap.yml"
4
+
5
+ def repo_map
6
+ ENV['REPO_MAP']
7
+ end
8
+
9
+ end
@@ -0,0 +1,24 @@
1
+ module RepoMap
2
+
3
+ repo_map = ENV['REPO_MAP']
4
+
5
+ def repo_map_validate
6
+ unless repo_map_exists?
7
+ File.new(repo_map, "w")
8
+ File.open(repo_map, "w") do |f|
9
+ f.write "---\n"
10
+ end
11
+ end
12
+ end
13
+
14
+ def has_git? path
15
+ File.directory? "#{File.expand_path(path)}/.git"
16
+ end
17
+
18
+ def repo_map_exists?
19
+ a = File.exist? repo_map
20
+ b = File.read(repo_map)!='' if a
21
+ a and b
22
+ end
23
+
24
+ end
@@ -0,0 +1,16 @@
1
+ module RepoMap
2
+
3
+ def list
4
+ repo_map_validate
5
+ hash = YAML::load(File.read(repo_map))
6
+ longest_name = 0
7
+ hash.each do |k,v|
8
+ longest_name = v[:name].length if v[:name].length > longest_name
9
+ end
10
+ hash.each do |key, value|
11
+ printf "%-#{longest_name}s %s\n", value[:name], key
12
+ end
13
+ exit 0
14
+ end
15
+
16
+ end
@@ -0,0 +1,21 @@
1
+ module RepoMap
2
+
3
+ def remove! path
4
+ repo_map_validate
5
+ full_path = File.expand_path(path)
6
+ basename = File.basename(full_path)
7
+ hash = YAML::load(File.read(repo_map))
8
+ if hash.has_key?(full_path.to_sym)
9
+ puts "repo: I'm removing '#{basename}' from '#{repo_map}'"
10
+ else
11
+ STDERR.puts "repo: I don't have this repository -- '#{full_path}'"
12
+ exit 1
13
+ end
14
+ hash.delete(full_path.to_sym)
15
+ File.open(repo_map, "w") do |f|
16
+ f.write hash.to_yaml
17
+ end
18
+ exit 0
19
+ end
20
+
21
+ end
@@ -0,0 +1,3 @@
1
+ module RepoMap
2
+ VERSION = '0.0.1'
3
+ end
data/lib/repomap.rb ADDED
@@ -0,0 +1,27 @@
1
+ require 'yaml'
2
+ require 'repomap/config'
3
+ require 'repomap/helpers'
4
+ require 'repomap/version'
5
+ require 'repomap/add'
6
+ require 'repomap/remove'
7
+ require 'repomap/list'
8
+
9
+ module RepoMap
10
+
11
+ # receive a hashmap like:
12
+ # {:add => 'path/to/repo/or/dir',
13
+ # :recursive => bool}, or
14
+ # {:list => bool}, or
15
+ # {:remove => 'path/to/repo/in/repomap'}
16
+ # Then, call appropriate functions.
17
+ def self.handle options
18
+ if options[:add] != '' and options[:add] != nil and options[:recursive]==true
19
+ add_recursive! options[:add]
20
+ elsif options[:add] != '' and options[:add] != nil and options[:recursive]==false
21
+ add! options[:add]
22
+ end
23
+ remove! options[:remove] if options[:remove] != '' and options[:remove] != nil
24
+ list if options[:list]
25
+ end
26
+
27
+ end
data/repomap.gemspec ADDED
@@ -0,0 +1,19 @@
1
+ $: << "#{File.dirname(__FILE__)}/lib"
2
+ require 'repomap'
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Gursimran Singh"]
6
+ gem.email = ["g@kilotau.com"]
7
+ gem.description = %q{RepoMap tracks your local git repositories.}
8
+ gem.summary = %q{Find and keep track of your local git repositories.}
9
+ gem.homepage = "http://github.com/gnarmis/RepoMap"
10
+
11
+ gem.add_development_dependency('rake')
12
+ gem.add_development_dependency('rspec')
13
+
14
+ gem.files = `git ls-files`.split($/)
15
+ gem.executables = gem.files.grep(%r{^bin/}).map {|f| File.basename(f)}
16
+ gem.name = "repomap"
17
+ gem.require_paths = ["lib"]
18
+ gem.version = RepoMap::VERSION
19
+ end
@@ -0,0 +1,41 @@
1
+ $: << "#{File.dirname(__FILE__)}/../lib"
2
+
3
+ require 'repomap'
4
+ require 'fileutils'
5
+
6
+ include FileUtils
7
+
8
+ module RepoMap
9
+ ENV['REPO_MAP'] = "#{File.dirname(__FILE__)}/../tmp/repomap.yml"
10
+ REPO1 = "#{File.dirname(__FILE__)}/../tmp/repo1"
11
+ end
12
+
13
+ include RepoMap
14
+
15
+ describe "RepoMap SubCommands" do
16
+
17
+ before :each do
18
+ mkdir_p "#{REPO1}/.git"
19
+ # so it's not empty...
20
+ touch "#{REPO1}/README"
21
+ end
22
+
23
+ after :each do
24
+ rm_f "#{REPO1}/.git"
25
+ end
26
+
27
+ after :all do
28
+ `rm -rf "#{File.dirname(__FILE__)}/../tmp"`
29
+ end
30
+
31
+ describe "#add!" do
32
+
33
+ it "should add a given path to ENV['REPO_MAP']" do
34
+ RepoMap.handle :add => REPO1, :recursive => false
35
+ hash = YAML::load(File.read(repo_map))
36
+ hash[File.expand_path(REPO1).to_sym][:name].should == File.basename(REPO1)
37
+ end
38
+
39
+ end
40
+
41
+ end
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: repomap
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Gursimran Singh
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-12-18 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: RepoMap tracks your local git repositories.
47
+ email:
48
+ - g@kilotau.com
49
+ executables:
50
+ - repo
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - .gitignore
55
+ - Gemfile
56
+ - LICENSE
57
+ - README.md
58
+ - Rakefile
59
+ - bin/repo
60
+ - lib/repomap.rb
61
+ - lib/repomap/add.rb
62
+ - lib/repomap/config.rb
63
+ - lib/repomap/helpers.rb
64
+ - lib/repomap/list.rb
65
+ - lib/repomap/remove.rb
66
+ - lib/repomap/version.rb
67
+ - repomap.gemspec
68
+ - spec/repoman_spec.rb
69
+ homepage: http://github.com/gnarmis/RepoMap
70
+ licenses: []
71
+ post_install_message:
72
+ rdoc_options: []
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ! '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ! '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ requirements: []
88
+ rubyforge_project:
89
+ rubygems_version: 1.8.24
90
+ signing_key:
91
+ specification_version: 3
92
+ summary: Find and keep track of your local git repositories.
93
+ test_files: []