git-make_mirror 1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 65d9ee5d3977f4ab59594d03dc21de92a31cecd4
4
+ data.tar.gz: d0355c1dfb37831d2d855e14f4e3bcba78132d14
5
+ SHA512:
6
+ metadata.gz: 5ff0ea7e7174e077714471284deae9c5678709aaf72c7ba5f3948ac95419ee54d0f2dd9b8d0dfb78e91182e9f240b353c92e7cf9906988740170802a231e3d0d
7
+ data.tar.gz: d82d7d09a3f8cf79193a63cb63c5abd5f67bd7d1b9ea642351bf6918efb95326ca5b0310b9c28ab47b41160c4a050f0179cedca1120ea583752c8e6d70911cce
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.2.2
5
+ before_install: gem install bundler -v 1.13.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in git-make_mirror.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Nathan Reed
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,30 @@
1
+ # git make-mirror
2
+
3
+ git-make_mirror is a utility for easily creating *non-bare* pushable remotes. This is very useful for creating deployment endpoints.
4
+
5
+ ## Installation
6
+
7
+ gem install git-make_mirror
8
+
9
+ ## Usage
10
+
11
+ git make-mirror [options] <remote_name>
12
+
13
+ For example the following will create a empty repository on the host given, and set the options so that it can be pushed to, even though it is not bare. A post-receive hook will reset the working directory to HEAD after every push.
14
+
15
+ git make-mirror reednj@twtxt.xyz:code/hello.git
16
+
17
+ When running the command from a git repository, the `-p` option will immediately push the current repository to the remote.
18
+
19
+ # will immediately push the current repo into hello.git
20
+ git make-mirror -p reednj@twtxt.xyz:code/hello.git
21
+
22
+ The `-r` option will add the remote to the current repository with the provided name.
23
+
24
+ # after running the repository will have the new remote 'prod'
25
+ git make-mirror -r prod reednj@twtxt.xyz:code/hello.git
26
+
27
+ ## License
28
+
29
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
30
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "git/make_mirror"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require 'git/make_mirror'
3
+ Git::MakeMirror::App.new.main
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'git/make_mirror/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "git-make_mirror"
8
+ spec.version = Git::MakeMirror::VERSION
9
+ spec.authors = ["Nathan Reed"]
10
+ spec.email = ["reednj@gmail.com"]
11
+
12
+ spec.summary = "Create a non-bare remote ready to accept pushes for deployment"
13
+ spec.homepage = "https://github.com/reednj/git-make_mirror"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.13"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_dependency 'trollop'
27
+ end
@@ -0,0 +1,62 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Aside from removing Ruby on Rails specific code this is taken verbatim from
4
+ # mislav's git-deploy (http://github.com/mislav/git-deploy) and it's awesome
5
+ # - Ryan Florence (http://ryanflorence.com)
6
+ #
7
+ # Install this hook to a remote repository with a working tree, when you push
8
+ # to it, this hook will reset the head so the files are updated
9
+
10
+ if ENV['GIT_DIR'] == '.'
11
+ # this means the script has been called as a hook, not manually.
12
+ # get the proper GIT_DIR so we can descend into the working copy dir;
13
+ # if we don't then `git reset --hard` doesn't affect the working tree.
14
+ Dir.chdir('..')
15
+ ENV['GIT_DIR'] = '.git'
16
+ end
17
+
18
+ cmd = %(bash -c "[ -f /etc/profile ] && source /etc/profile; echo $PATH")
19
+ envpath = IO.popen(cmd, 'r') { |io| io.read.chomp }
20
+ ENV['PATH'] = envpath
21
+
22
+ # find out the current branch
23
+ head = `git symbolic-ref HEAD`.chomp
24
+ # abort if we're on a detached head
25
+ exit unless $?.success?
26
+
27
+ oldrev = newrev = nil
28
+ null_ref = '0' * 40
29
+
30
+ # read the STDIN to detect if this push changed the current branch
31
+ while newrev.nil? and gets
32
+ # each line of input is in form of "<oldrev> <newrev> <refname>"
33
+ revs = $_.split
34
+ oldrev, newrev = revs if head == revs.pop
35
+ end
36
+
37
+ # abort if there's no update, or in case the branch is deleted
38
+ exit if newrev.nil? or newrev == null_ref
39
+
40
+ # update the working copy
41
+ `umask 002 && git reset --hard`
42
+
43
+ # now find the deployment script and execute it
44
+ git_dir = ENV['GIT_DIR']
45
+ deploy_scripts = ['deploy.sh', 'config/deploy.sh']
46
+ deploy_hook_name = 'deploy'
47
+
48
+ # find the deployment script and copy it to the hooks dir
49
+ deploy_scripts.each do |file|
50
+ path = "#{git_dir}/../#{file}"
51
+
52
+ if File.exists? path
53
+ `cp #{path} #{git_dir}/hooks/#{deploy_hook_name}`
54
+ `chmod 711 #{git_dir}/hooks/#{deploy_hook_name}`
55
+ break
56
+ end
57
+ end
58
+
59
+ # execute the deployment hook, if it exists
60
+ if File.exists? "#{git_dir}/hooks/#{deploy_hook_name}"
61
+ system "#{git_dir}/hooks/#{deploy_hook_name}"
62
+ end
@@ -0,0 +1,5 @@
1
+ module Git
2
+ module MakeMirror
3
+ VERSION = "1.0.1"
4
+ end
5
+ end
@@ -0,0 +1,94 @@
1
+ require 'trollop'
2
+ require "git/make_mirror/version"
3
+
4
+ module Git
5
+ module MakeMirror
6
+ class App
7
+
8
+ def main
9
+ opts = Trollop::options do
10
+ version "git-make-mirror #{Git::MakeMirror::VERSION} (c) 2017 @reednj (reednj@gmail.com)"
11
+ banner "Usage: git make-mirror [options] [remote]"
12
+ opt :remote, "create a remote in the local repository", :type => :string
13
+ opt :push, "push to the newly created mirror"
14
+ end
15
+
16
+ git_remote_name = nil
17
+
18
+ puts "creating remote repository"
19
+ self.create_repository
20
+
21
+ puts "copying post-receive hook"
22
+ self.copy_hook
23
+
24
+ if !opts[:remote].nil?
25
+ git_remote_name = opts[:remote]
26
+ sh "git remote add #{git_remote_name} #{remote_url}"
27
+ end
28
+
29
+ if opts[:push]
30
+ sh "git push #{git_remote_name || remote_url} master"
31
+ end
32
+
33
+ end
34
+
35
+ def sh(cmd)
36
+ puts cmd
37
+ system cmd
38
+ end
39
+
40
+ def local_hooks_dir
41
+ @hooks_dir ||= File.join(File.dirname(__FILE__), 'hooks')
42
+ end
43
+
44
+ def remote_url
45
+ ARGV.last.strip
46
+ end
47
+
48
+ def remote
49
+ @remote ||= parse_remote(self.remote_url)
50
+ end
51
+
52
+ def server
53
+ @server ||= SSHCmd.new remote[:host]
54
+ end
55
+
56
+ def parse_remote(remote)
57
+ a = remote.split(':')
58
+ { :host => a[0], :path => a[1] }
59
+ end
60
+
61
+ def create_repository
62
+ server.exec [
63
+ "mkdir -p #{remote[:path]}",
64
+ "cd #{remote[:path]}",
65
+ 'git init',
66
+ 'git config receive.denyCurrentBranch ignore'
67
+ ]
68
+ end
69
+
70
+ def copy_hook
71
+ local_hook_file = File.join local_hooks_dir, 'post-receive.rb'
72
+ remote_hook_file = File.join remote[:path], '.git/hooks/post-receive'
73
+ server.scp local_hook_file, remote_hook_file
74
+ server.exec "chmod 775 #{remote_hook_file}"
75
+ end
76
+ end
77
+
78
+ end
79
+ end
80
+
81
+ class SSHCmd
82
+ def initialize(server)
83
+ @server = server
84
+ end
85
+
86
+ def exec(cmd)
87
+ cmd = cmd.join ' && ' if cmd.is_a? Array
88
+ `ssh #{@server} '#{cmd}'`
89
+ end
90
+
91
+ def scp(from, to)
92
+ `scp #{from} #{@server}:#{to}`
93
+ end
94
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: git-make_mirror
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Nathan Reed
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-04-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.13'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.13'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: trollop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description:
56
+ email:
57
+ - reednj@gmail.com
58
+ executables:
59
+ - git-make-mirror
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - ".travis.yml"
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - bin/console
70
+ - bin/setup
71
+ - exe/git-make-mirror
72
+ - git-make_mirror.gemspec
73
+ - lib/git/hooks/post-receive.rb
74
+ - lib/git/make_mirror.rb
75
+ - lib/git/make_mirror/version.rb
76
+ homepage: https://github.com/reednj/git-make_mirror
77
+ licenses:
78
+ - MIT
79
+ metadata: {}
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 2.6.6
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: Create a non-bare remote ready to accept pushes for deployment
100
+ test_files: []