gir 0.0.0 → 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.
- checksums.yaml +4 -4
- data/bin/girc +95 -0
- data/lib/gir.rb +74 -2
- data/lib/gir/git.rb +21 -0
- data/lib/gir/version.rb +1 -1
- metadata +5 -5
- data/.gitignore +0 -16
- data/LICENSE.txt +0 -22
- data/README.md +0 -31
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a6397b8c02a1291b4c7407ddd32b0eabf502ee8d
|
4
|
+
data.tar.gz: f09d3545aa22dc477a9ea9601adb0aca359463cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 376c98a5b13e90c5ddf72fe1aa5cec17894577b917804e8edf9963b02537b0e6ca23ffa4113d37730356cf5c4bf4aa3c9ed3b3e099acd4d75a7700cc84f903a6
|
7
|
+
data.tar.gz: 84b3a70bf9082b7011f7e8cc36074fbf534d54768c2baeee97ae23a5f61b3ffce7f1c700df41043198594ff9156b3497e6616a34e663823faff2f123d4f5ea94
|
data/bin/girc
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'json'
|
4
|
+
require 'cmdparser'
|
5
|
+
require 'fileutils'
|
6
|
+
require_relative '../lib/gir.rb'
|
7
|
+
|
8
|
+
def show_git_wrapper gitpath
|
9
|
+
print <<-EOS
|
10
|
+
gir(){
|
11
|
+
gitpath=#{gitpath}
|
12
|
+
if [ -e #{gir} ]; then
|
13
|
+
girc git $@
|
14
|
+
else
|
15
|
+
$gitpath $@
|
16
|
+
fi
|
17
|
+
}
|
18
|
+
EOS
|
19
|
+
end
|
20
|
+
|
21
|
+
def gitconfig
|
22
|
+
Git::get_local_repo_dir('./.git/config')
|
23
|
+
end
|
24
|
+
|
25
|
+
def gir
|
26
|
+
Git::get_local_repo_dir('.gir',safe = true)
|
27
|
+
end
|
28
|
+
|
29
|
+
def sshkey username
|
30
|
+
Gir::user_file(username,Gir::SSH_KEY)
|
31
|
+
end
|
32
|
+
|
33
|
+
CmdParser.new{
|
34
|
+
|
35
|
+
on 'git' do
|
36
|
+
profile = JSON.load(File.read(gir))
|
37
|
+
system "GIT_KEY=#{sshkey(profile['user'])} GIT_SSH=#{Gir::script_path(Gir::GIT_SSH)} #{ARGV.join(' ')}"
|
38
|
+
end
|
39
|
+
|
40
|
+
on 'add' do |user|
|
41
|
+
# replace checking
|
42
|
+
Gir::get_gir_home
|
43
|
+
unless user && user != ''
|
44
|
+
puts '-> girc add user'
|
45
|
+
exit
|
46
|
+
end
|
47
|
+
|
48
|
+
has_profile = Gir::has_profile? user
|
49
|
+
unless has_profile
|
50
|
+
Gir::create_gir_user(user)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
on 'local' do |user|
|
55
|
+
profile = {
|
56
|
+
:user => user
|
57
|
+
}
|
58
|
+
open(gir, 'w') do |fp|
|
59
|
+
JSON.dump(profile, fp)
|
60
|
+
end
|
61
|
+
# have git repository and have user config
|
62
|
+
# if true, merge user config with git repository's config
|
63
|
+
if !!gitconfig && FileTest.exists?(gitconfig) && FileTest.exists?(Gir::user_file(user,Gir::GIT_CONFIG))
|
64
|
+
config = GitConfigIO::load(Gir::user_file(user,Gir::GIT_CONFIG))
|
65
|
+
GitConfigIO::merge!(gitconfig,config)
|
66
|
+
elsif !FileTest.exists?(Gir::user_file(user,Gir::GIT_CONFIG))
|
67
|
+
puts "-> girc add #{user}"
|
68
|
+
else
|
69
|
+
puts "can't patch local gitconfig"
|
70
|
+
puts "-> git clone repo && cd repo && girc local #{user}"
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
on 'init' do |option|
|
75
|
+
if '-' == option
|
76
|
+
git_path = `which git`.chomp
|
77
|
+
if git_path.length == 0
|
78
|
+
puts 'install git'
|
79
|
+
exit
|
80
|
+
end
|
81
|
+
show_git_wrapper(git_path)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
on 'install' do
|
86
|
+
@install_proc = Proc.new do |path = '~/.gir'|
|
87
|
+
Gir::install(path)
|
88
|
+
end
|
89
|
+
@install_proc.call unless ARGV.include? '--prefix'
|
90
|
+
end
|
91
|
+
|
92
|
+
on 'install','--prefix' do |path = '~/gir'|
|
93
|
+
@install_proc.call path
|
94
|
+
end
|
95
|
+
}.invoke
|
data/lib/gir.rb
CHANGED
@@ -1,5 +1,77 @@
|
|
1
|
-
|
1
|
+
require_relative './gir/git.rb'
|
2
|
+
require 'fileutils'
|
3
|
+
require 'gitconfigio'
|
2
4
|
|
3
5
|
module Gir
|
4
|
-
|
6
|
+
HOME = `echo $GIR_HOME`.chomp
|
7
|
+
SSH_KEY = 'ssh_key'
|
8
|
+
GIT_CONFIG = '.gitconfig'
|
9
|
+
GIT_SSH = 'git_ssh'
|
10
|
+
EDITOR = ->{
|
11
|
+
which = lambda{|which|
|
12
|
+
`which #{which}`.chomp.length > 0 ? which : false
|
13
|
+
}
|
14
|
+
return which.call(ENV["EDITOR"]) || which.call('vi') || which.call('emacs') ||
|
15
|
+
which.call('vim') || which.call('nano') || which.call('cat')
|
16
|
+
}.call
|
17
|
+
|
18
|
+
def self.get_gir_home
|
19
|
+
unless FileTest.exists? HOME
|
20
|
+
puts '-> girc install'
|
21
|
+
exit
|
22
|
+
end
|
23
|
+
HOME
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.live_user username
|
27
|
+
FileTest.exists? user_path username
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.script_path script
|
31
|
+
"#{HOME}/script/#{script}"
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.user_path user
|
35
|
+
"#{HOME}/user/#{user}"
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.user_file user,file
|
39
|
+
user_path(user + "/#{file}")
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.has_profile? username
|
43
|
+
FileTest.exists?(user_path(username))
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.install path
|
47
|
+
path = File.expand_path(path.sub(/\/$/,''))
|
48
|
+
FileUtils.mkdir_p path + '/user'
|
49
|
+
FileUtils.mkdir_p path + '/script'
|
50
|
+
File.write("#{path}/script/#{GIT_SSH}",<<-EOS)
|
51
|
+
#!/bin/sh
|
52
|
+
exec ssh -i $GIT_KEY "$@"
|
53
|
+
EOS
|
54
|
+
File.chmod(0777,"#{path}/script/#{GIT_SSH}")
|
55
|
+
print <<-EOS
|
56
|
+
echo 'eval "$(girc init -)"' >> ~/.bash_profile
|
57
|
+
echo 'export GIR_HOME=#{path}' >> ~/.bash_profile
|
58
|
+
EOS
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.create_gir_user user
|
62
|
+
puts "create #{user}'s dir"
|
63
|
+
FileUtils.mkdir_p user_path user
|
64
|
+
puts "create ssh-key #=>"
|
65
|
+
system "ssh-keygen -t rsa -f #{user_file user,SSH_KEY}"
|
66
|
+
# create gitconfign
|
67
|
+
File.write("#{user_file user,GIT_CONFIG}",<<-EOS)
|
68
|
+
# #{user}'s gitconfig\n
|
69
|
+
[user]
|
70
|
+
name = #{user}
|
71
|
+
mail = #{user}@mail.com
|
72
|
+
email = #{user}@mail.com
|
73
|
+
EOS
|
74
|
+
system "#{EDITOR} #{user_file user,GIT_CONFIG}"
|
75
|
+
end
|
76
|
+
|
5
77
|
end
|
data/lib/gir/git.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
module Git
|
2
|
+
def self.get_local_repo safe = false
|
3
|
+
path = Dir.getwd
|
4
|
+
until path == ''
|
5
|
+
local = path + '/.git'
|
6
|
+
return local if FileTest.exists? local
|
7
|
+
path.sub! /\/((?!\/).)+$/,''
|
8
|
+
end
|
9
|
+
safe ? Dir.getwd + '/': nil
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.get_local_repo_dir file = '' ,safe = false
|
13
|
+
repo = self.get_local_repo safe
|
14
|
+
if repo
|
15
|
+
repo.sub! /#{file == '' ? '\/' : ''}\.git$/,''
|
16
|
+
repo += file.sub /^\//,''
|
17
|
+
end
|
18
|
+
repo
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
data/lib/gir/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gir
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mocchi
|
@@ -83,19 +83,19 @@ dependencies:
|
|
83
83
|
description: change git user
|
84
84
|
email:
|
85
85
|
- boom.boom.planet@gmail.com
|
86
|
-
executables:
|
86
|
+
executables:
|
87
|
+
- girc
|
87
88
|
extensions: []
|
88
89
|
extra_rdoc_files: []
|
89
90
|
files:
|
90
|
-
- ".gitignore"
|
91
91
|
- ".rspec"
|
92
92
|
- ".travis.yml"
|
93
93
|
- Gemfile
|
94
|
-
- LICENSE.txt
|
95
|
-
- README.md
|
96
94
|
- Rakefile
|
95
|
+
- bin/girc
|
97
96
|
- gir.gemspec
|
98
97
|
- lib/gir.rb
|
98
|
+
- lib/gir/git.rb
|
99
99
|
- lib/gir/version.rb
|
100
100
|
- spec/gir_spec.rb
|
101
101
|
- spec/spec_helper.rb
|
data/.gitignore
DELETED
data/LICENSE.txt
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
Copyright (c) 2015 mkalloc
|
2
|
-
|
3
|
-
MIT License
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
-
a copy of this software and associated documentation files (the
|
7
|
-
"Software"), to deal in the Software without restriction, including
|
8
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
-
permit persons to whom the Software is furnished to do so, subject to
|
11
|
-
the following conditions:
|
12
|
-
|
13
|
-
The above copyright notice and this permission notice shall be
|
14
|
-
included in all copies or substantial portions of the Software.
|
15
|
-
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
# Gir
|
2
|
-
|
3
|
-
TODO: Write a gem description
|
4
|
-
|
5
|
-
## Installation
|
6
|
-
|
7
|
-
Add this line to your application's Gemfile:
|
8
|
-
|
9
|
-
```ruby
|
10
|
-
gem 'gir'
|
11
|
-
```
|
12
|
-
|
13
|
-
And then execute:
|
14
|
-
|
15
|
-
$ bundle
|
16
|
-
|
17
|
-
Or install it yourself as:
|
18
|
-
|
19
|
-
$ gem install gir
|
20
|
-
|
21
|
-
## Usage
|
22
|
-
|
23
|
-
TODO: Write usage instructions here
|
24
|
-
|
25
|
-
## Contributing
|
26
|
-
|
27
|
-
1. Fork it ( https://github.com/[my-github-username]/gir/fork )
|
28
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
-
5. Create a new Pull Request
|