absgit 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +2 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +34 -0
- data/LICENCE.txt +4 -0
- data/README.md +22 -0
- data/Rakefile +20 -0
- data/absgit.gemspec +51 -0
- data/bin/absgit +7 -0
- data/doc/absgit.md +55 -0
- data/lib/absgit/version.rb +3 -0
- data/lib/absgit.rb +99 -0
- data/test/absgit_test.rb +116 -0
- metadata +127 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7f26cd5efa247302f66c97d4ef3f6118d2b6a576
|
4
|
+
data.tar.gz: 2af40a800b06f4085875b6ae54935dfb0c97e53d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 114ada2e52cdde5bfea375e52b75721a092a71f299089a2b6bb2350b618c4a1d1a19024b796d04dd73e741924fd9e44d139f5f6a2d92220e2bc4f52d066d3ba3
|
7
|
+
data.tar.gz: 9e86941d8c7a81a97746faca2cbccb2bf0b52569a523d886bf241394a4abc4e66323ba76f2fc6dc7a9e326670cfa544f21486acfae18e26c91b957cc9a694a20
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
absgit (0.1.0)
|
5
|
+
methadone (~> 1.2.6)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
ansi (1.4.3)
|
11
|
+
builder (3.0.4)
|
12
|
+
hashie (2.0.4)
|
13
|
+
methadone (1.2.6)
|
14
|
+
bundler
|
15
|
+
minitest (4.7.3)
|
16
|
+
minitest-reporters (0.14.17)
|
17
|
+
ansi
|
18
|
+
builder
|
19
|
+
minitest (>= 2.12, < 5.0)
|
20
|
+
powerbar
|
21
|
+
powerbar (1.0.11)
|
22
|
+
ansi (~> 1.4.0)
|
23
|
+
hashie (>= 1.1.0)
|
24
|
+
rake (10.0.4)
|
25
|
+
|
26
|
+
PLATFORMS
|
27
|
+
ruby
|
28
|
+
|
29
|
+
DEPENDENCIES
|
30
|
+
absgit!
|
31
|
+
bundler (~> 1.3)
|
32
|
+
minitest (~> 4.0)
|
33
|
+
minitest-reporters (~> 0.14.17)
|
34
|
+
rake
|
data/LICENCE.txt
ADDED
data/README.md
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# absgit
|
2
|
+
|
3
|
+
## Introduction
|
4
|
+
|
5
|
+
This is the repository for a Ruby gem
|
6
|
+
called `absgit`.
|
7
|
+
It provides a program of the same name
|
8
|
+
which
|
9
|
+
allows one to manipulate files in a Git repository,
|
10
|
+
regardless of whether one is inside it.
|
11
|
+
|
12
|
+
## Installation
|
13
|
+
|
14
|
+
To install the gem, give this command:
|
15
|
+
|
16
|
+
gem install absgit
|
17
|
+
|
18
|
+
Ruby 2 is required.
|
19
|
+
|
20
|
+
## Documentation
|
21
|
+
|
22
|
+
See [here](doc/absgit.md).
|
data/Rakefile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
|
3
|
+
desc 'Run the test suite'
|
4
|
+
task :test do
|
5
|
+
#> we need to set RUBYLIB, because the test suite
|
6
|
+
# invokes the application as a separate process
|
7
|
+
|
8
|
+
system(
|
9
|
+
{
|
10
|
+
'RUBYLIB' =>
|
11
|
+
(
|
12
|
+
ENV.fetch('RUBYLIB', '').split(':') +
|
13
|
+
[File.join(__dir__, 'lib')]
|
14
|
+
).join(':')
|
15
|
+
},
|
16
|
+
FileUtils::RUBY, 'test/absgit_test.rb'
|
17
|
+
)
|
18
|
+
end
|
19
|
+
|
20
|
+
task :default => :test
|
data/absgit.gemspec
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
require 'absgit/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = "absgit"
|
9
|
+
spec.version = Absgit::VERSION
|
10
|
+
spec.authors = ["Ruafozy"]
|
11
|
+
|
12
|
+
spec.summary =
|
13
|
+
%q{Allow manipulating Git repository files outside a repository}
|
14
|
+
|
15
|
+
spec.description = %q{
|
16
|
+
This gem contains a program which allows one to
|
17
|
+
manipulate files in a Git repository,
|
18
|
+
regardless of whether one is inside it.
|
19
|
+
}.split.join(' ')
|
20
|
+
|
21
|
+
spec.homepage = "https://github.com/ruafozy/absgit"
|
22
|
+
spec.license = "MIT"
|
23
|
+
|
24
|
+
spec.files = `git ls-files`.split($/)
|
25
|
+
|
26
|
+
spec.required_ruby_version = '>= 2.0.0'
|
27
|
+
|
28
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
29
|
+
spec.test_files = spec.files.grep(%r{\Atest\z/})
|
30
|
+
spec.require_paths = ["lib"]
|
31
|
+
|
32
|
+
[
|
33
|
+
['methadone', ['~> 1.2.6']],
|
34
|
+
].each do |name, ver|
|
35
|
+
spec.add_runtime_dependency(name, ver)
|
36
|
+
end
|
37
|
+
|
38
|
+
[
|
39
|
+
['bundler', ['~> 1.3']],
|
40
|
+
['minitest', ['~> 4.0']],
|
41
|
+
['minitest-reporters', ['~> 0.14.17']],
|
42
|
+
['rake'],
|
43
|
+
].each do |gem_info|
|
44
|
+
spec.add_development_dependency(*gem_info)
|
45
|
+
end
|
46
|
+
|
47
|
+
#> there seems to be no way to specify in the gemspec
|
48
|
+
# that rdoc documentation should not be generated.
|
49
|
+
# see http://stackoverflow.com/q/16167876
|
50
|
+
spec.has_rdoc = false
|
51
|
+
end
|
data/bin/absgit
ADDED
data/doc/absgit.md
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
## The Problem
|
2
|
+
|
3
|
+
You can do this:
|
4
|
+
|
5
|
+
cd /
|
6
|
+
svn commit --message blah /some/absolute/path
|
7
|
+
|
8
|
+
but you can't do this:
|
9
|
+
|
10
|
+
cd /
|
11
|
+
git commit --message blah /some/absolute/path
|
12
|
+
|
13
|
+
More generally,
|
14
|
+
Git requires you to be within the
|
15
|
+
repository, whereas Subversion does not.
|
16
|
+
|
17
|
+
## The solution
|
18
|
+
|
19
|
+
A program called `absgit`.
|
20
|
+
To use it, simply type your desired Git
|
21
|
+
command, replacing the initial "git" with "absgit".
|
22
|
+
For example:
|
23
|
+
|
24
|
+
absgit commit --message blah /some/absolute/path
|
25
|
+
|
26
|
+
Its logic is very simple.
|
27
|
+
It skips over the Git subcommand and iterates
|
28
|
+
over the remaining arguments, looking
|
29
|
+
for the first argument which contains a slash and
|
30
|
+
names a path inside a Git repository.
|
31
|
+
If it finds such an argument,
|
32
|
+
it infers `GIT_DIR` and `GIT_WORK_TREE`,
|
33
|
+
then invokes `git` with these
|
34
|
+
variables in its environment.
|
35
|
+
|
36
|
+
If it finds no such argument,
|
37
|
+
then it simply invokes `git` with an
|
38
|
+
unchanged environment.
|
39
|
+
For example, the following
|
40
|
+
two commands are essentially equivalent:
|
41
|
+
|
42
|
+
absgit log -3
|
43
|
+
|
44
|
+
git log -3
|
45
|
+
|
46
|
+
## Options
|
47
|
+
|
48
|
+
`absgit` accepts the `--help` and `--version` options.
|
49
|
+
|
50
|
+
## Origin of name
|
51
|
+
|
52
|
+
The software is commonly used in conjunction with
|
53
|
+
absolute pathnames,
|
54
|
+
so the prefix "abs" was chosen,
|
55
|
+
as a short version of "absolute".
|
data/lib/absgit.rb
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
require 'absgit/version'
|
2
|
+
require 'methadone'
|
3
|
+
require 'optparse'
|
4
|
+
require 'pathname'
|
5
|
+
|
6
|
+
class Absgit
|
7
|
+
include Methadone::CLILogging
|
8
|
+
|
9
|
+
GIT_DIR_BASE = '.git'
|
10
|
+
PROGRAM_NAME = 'absgit'
|
11
|
+
|
12
|
+
def initialize(args)
|
13
|
+
@args = args
|
14
|
+
@options = {}
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.get_repo_path(file_name)
|
18
|
+
path = Pathname.new(file_name)
|
19
|
+
|
20
|
+
if path.exist?
|
21
|
+
path.realpath.ascend do |path2|
|
22
|
+
if (path2 + '.git').exist?
|
23
|
+
return path2
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def option_parser
|
30
|
+
OptionParser.new do |parser|
|
31
|
+
parser.program_name = PROGRAM_NAME
|
32
|
+
parser.banner = "Usage: #{PROGRAM_NAME} [options] [GIT_SUBCOMMAND]"
|
33
|
+
|
34
|
+
parser.on('--debug', 'Show debugging information') do
|
35
|
+
@options[:debug] = true
|
36
|
+
end
|
37
|
+
|
38
|
+
parser.on('--help', 'Show this usage summary') do
|
39
|
+
@options[:help] = true
|
40
|
+
end
|
41
|
+
|
42
|
+
parser.on('--version', 'Show program name and version') do
|
43
|
+
@options[:version] = true
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def run
|
49
|
+
begin
|
50
|
+
option_parser.order!
|
51
|
+
rescue OptionParser::ParseError
|
52
|
+
$stderr.puts 'Error: incorrect usage'
|
53
|
+
$stderr.puts ''
|
54
|
+
$stderr.puts option_parser
|
55
|
+
exit(1)
|
56
|
+
end
|
57
|
+
|
58
|
+
if @options[:debug]
|
59
|
+
logger.error_level = Logger::Severity::DEBUG
|
60
|
+
end
|
61
|
+
|
62
|
+
debug(@options.inspect)
|
63
|
+
debug(@args.inspect)
|
64
|
+
|
65
|
+
if @options[:version]
|
66
|
+
puts "#{PROGRAM_NAME} #{VERSION}"
|
67
|
+
elsif @options[:help]
|
68
|
+
puts option_parser
|
69
|
+
else
|
70
|
+
repo_path =
|
71
|
+
@args[1..-1].grep(%r{/}).each_with_object(nil) { |arg|
|
72
|
+
repo = self.class.get_repo_path(arg)
|
73
|
+
break repo if !repo.nil?
|
74
|
+
}
|
75
|
+
|
76
|
+
env =
|
77
|
+
if repo_path.nil?
|
78
|
+
{}
|
79
|
+
else
|
80
|
+
{
|
81
|
+
'GIT_DIR' => (repo_path + GIT_DIR_BASE).to_s,
|
82
|
+
'GIT_WORK_TREE' => repo_path.to_s,
|
83
|
+
}
|
84
|
+
end
|
85
|
+
|
86
|
+
#< it seems better to use environment variables
|
87
|
+
# rather than "--git-dir" and "--work-tree", because
|
88
|
+
# environment variables will be inherited by processes
|
89
|
+
# spawned by git aliases.
|
90
|
+
|
91
|
+
command = ['git'] + @args
|
92
|
+
debug(command.inspect)
|
93
|
+
debug(env.inspect)
|
94
|
+
system(env, *command)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
# vim: set syntax=ruby:
|
data/test/absgit_test.rb
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
gem 'minitest', '~> 4.0'
|
3
|
+
|
4
|
+
require 'minitest/unit'
|
5
|
+
MiniTest::Unit.autorun
|
6
|
+
|
7
|
+
require "minitest/reporters"
|
8
|
+
MiniTest::Reporters.use!
|
9
|
+
|
10
|
+
require 'absgit'
|
11
|
+
require 'fileutils'
|
12
|
+
require 'shellwords'
|
13
|
+
require 'tmpdir'
|
14
|
+
|
15
|
+
class AbsgitTest < MiniTest::Unit::TestCase
|
16
|
+
APP_PATH = File.expand_path(
|
17
|
+
"../../bin/#{Absgit::PROGRAM_NAME}",
|
18
|
+
__FILE__
|
19
|
+
)
|
20
|
+
APP_PATH_ESC = Shellwords.escape(APP_PATH)
|
21
|
+
|
22
|
+
def setup
|
23
|
+
@temp_dir = Dir.mktmpdir
|
24
|
+
|
25
|
+
# puts "dir: #@temp_dir"
|
26
|
+
end
|
27
|
+
|
28
|
+
def teardown
|
29
|
+
FileUtils.rm_r(@temp_dir, secure: true)
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_symlinks_resolved
|
33
|
+
Dir.chdir(@temp_dir) do
|
34
|
+
# Given
|
35
|
+
|
36
|
+
repo = 'a1/a2/a3/repo'
|
37
|
+
repo_abs = File.absolute_path(repo)
|
38
|
+
|
39
|
+
repo_file = File.join(repo, 'b1/b2/b3/file')
|
40
|
+
repo_file_abs = File.absolute_path(repo_file)
|
41
|
+
|
42
|
+
symlink = 'd/symlink'
|
43
|
+
|
44
|
+
FileUtils.makedirs(File.dirname(repo_file))
|
45
|
+
FileUtils.touch(repo_file)
|
46
|
+
|
47
|
+
Dir.mkdir(File.dirname(symlink))
|
48
|
+
File.symlink(repo_file_abs, symlink)
|
49
|
+
|
50
|
+
system 'git', 'init', '--quiet', repo
|
51
|
+
|
52
|
+
# When & Then
|
53
|
+
|
54
|
+
assert_equal(repo_abs, Absgit.get_repo_path(symlink).to_s)
|
55
|
+
assert_equal(
|
56
|
+
repo_abs, Absgit.get_repo_path(File.absolute_path(symlink)).to_s
|
57
|
+
)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_file_not_in_repo
|
62
|
+
f = '/dev/null'
|
63
|
+
|
64
|
+
if !File.exist?(f)
|
65
|
+
skip
|
66
|
+
else
|
67
|
+
assert_nil(Absgit.get_repo_path(f))
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_commit_does_not_require_chdir_to_repo
|
72
|
+
Dir.chdir(@temp_dir) do
|
73
|
+
# Given
|
74
|
+
|
75
|
+
repo = 'repo'
|
76
|
+
repo_file = File.join(repo, 'file')
|
77
|
+
repo_file_abs = File.absolute_path(repo_file)
|
78
|
+
|
79
|
+
Dir.mkdir(repo)
|
80
|
+
system 'git', 'init', '--quiet', repo
|
81
|
+
IO.write(repo_file, "blah\n")
|
82
|
+
|
83
|
+
# When
|
84
|
+
|
85
|
+
system(
|
86
|
+
"#{APP_PATH_ESC} add #{repo_file_abs.shellescape}"
|
87
|
+
)
|
88
|
+
|
89
|
+
system(
|
90
|
+
"#{APP_PATH_ESC} commit --quiet --message blah " +
|
91
|
+
repo_file_abs.shellescape
|
92
|
+
)
|
93
|
+
|
94
|
+
# Then
|
95
|
+
|
96
|
+
Dir.chdir(repo) do
|
97
|
+
assert_equal("1\n", `git rev-list --count HEAD`)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_help_message_is_output
|
103
|
+
assert_match(/--help\b/, `#{APP_PATH_ESC} --help`)
|
104
|
+
end
|
105
|
+
|
106
|
+
def test_options_for_git_are_left_alone
|
107
|
+
refute_match(
|
108
|
+
/--help\b/,
|
109
|
+
%x{
|
110
|
+
#> any program that consumes its input will do
|
111
|
+
# instead of "wc"
|
112
|
+
PAGER=wc #{APP_PATH_ESC} log --help
|
113
|
+
}
|
114
|
+
)
|
115
|
+
end
|
116
|
+
end
|
metadata
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: absgit
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ruafozy
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-05-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: methadone
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.2.6
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.2.6
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '4.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '4.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitest-reporters
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.14.17
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.14.17
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: This gem contains a program which allows one to manipulate files in a
|
84
|
+
Git repository, regardless of whether one is inside it.
|
85
|
+
email:
|
86
|
+
executables:
|
87
|
+
- absgit
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- .gitignore
|
92
|
+
- Gemfile
|
93
|
+
- Gemfile.lock
|
94
|
+
- LICENCE.txt
|
95
|
+
- README.md
|
96
|
+
- Rakefile
|
97
|
+
- absgit.gemspec
|
98
|
+
- bin/absgit
|
99
|
+
- doc/absgit.md
|
100
|
+
- lib/absgit.rb
|
101
|
+
- lib/absgit/version.rb
|
102
|
+
- test/absgit_test.rb
|
103
|
+
homepage: https://github.com/ruafozy/absgit
|
104
|
+
licenses:
|
105
|
+
- MIT
|
106
|
+
metadata: {}
|
107
|
+
post_install_message:
|
108
|
+
rdoc_options: []
|
109
|
+
require_paths:
|
110
|
+
- lib
|
111
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - '>='
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: 2.0.0
|
116
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - '>='
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
requirements: []
|
122
|
+
rubyforge_project:
|
123
|
+
rubygems_version: 2.0.0
|
124
|
+
signing_key:
|
125
|
+
specification_version: 4
|
126
|
+
summary: Allow manipulating Git repository files outside a repository
|
127
|
+
test_files: []
|