absgit 0.1.3 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e791e4bf577e3a1e58ac8f959f0227ed4933a595
4
- data.tar.gz: f762c30f32481f37064411d076ce2bcaebd3ca0f
3
+ metadata.gz: 3e5b421181caae16aa6117e6b3a69da27869d11e
4
+ data.tar.gz: 6018b58723501e31f4d410d56035467a314f0cba
5
5
  SHA512:
6
- metadata.gz: 7bd814e27cf3029fa9c3b168b8edb0e938f419daf82c16226110d3cb5bd086d4526a2189bbb2a3094745db17cdb0cd3667ec409525d7f324ccfef0d8215d6833
7
- data.tar.gz: 7d46df305375c76723f9a6f1eee238fdab6eea57a900aba16bb4784d954f13e95a3f2f09c975c9a4b3843b9aec8ea6e4a95109e42dcd5ec2c73bcdfc49b24843
6
+ metadata.gz: e018de14b4a7f2267a7d7a9f62cd821ba9d9c9eabaa841595b168f8d681d6898ed4a4409f04d6ff430021fa57767e7d1284f723684463fd1058ab785bc6d783b
7
+ data.tar.gz: d78ac731320c1f902af6d320858344766b5ae90cd033acf45156760cf00e3ef9e531514132982f5bb17a552b0bc82c8147092466bde300df03f9171e018b2624
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in absgit.gemspec
4
- gemspec
1
+ gem 'methadone', '~> 1.3.0'
2
+ gem 'minitest', '~> 4.7.3'
3
+ gem 'minitest-reporters', '~> 0.14.17'
4
+ gem 'rake', '~> 10.0.4'
data/Gemfile.lock CHANGED
@@ -1,16 +1,9 @@
1
- PATH
2
- remote: .
3
- specs:
4
- absgit (0.1.0)
5
- methadone (~> 1.2.6)
6
-
7
1
  GEM
8
- remote: https://rubygems.org/
9
2
  specs:
10
3
  ansi (1.4.3)
11
4
  builder (3.0.4)
12
5
  hashie (2.0.4)
13
- methadone (1.2.6)
6
+ methadone (1.3.0)
14
7
  bundler
15
8
  minitest (4.7.3)
16
9
  minitest-reporters (0.14.17)
@@ -27,8 +20,7 @@ PLATFORMS
27
20
  ruby
28
21
 
29
22
  DEPENDENCIES
30
- absgit!
31
- bundler (~> 1.3)
32
- minitest (~> 4.0)
23
+ methadone (~> 1.3.0)
24
+ minitest (~> 4.7.3)
33
25
  minitest-reporters (~> 0.14.17)
34
- rake
26
+ rake (~> 10.0.4)
data/README.md CHANGED
@@ -7,7 +7,7 @@ called `absgit`.
7
7
  It provides a program of the same name
8
8
  which
9
9
  allows one to manipulate files in a Git repository,
10
- regardless of whether one is inside it.
10
+ even if one's working directory is outside it.
11
11
 
12
12
  ## Installation
13
13
 
data/Rakefile CHANGED
@@ -1,7 +1,19 @@
1
1
  require 'bundler/gem_tasks'
2
2
 
3
+ desc 'Run absgit'
4
+ task :run, [:absgit_args] do |dummy, args|
5
+ system(
6
+ *with_bundler(
7
+ 'ruby', '-I', 'lib', 'bin/absgit', *args.absgit_args.split
8
+ )
9
+ )
10
+ end
11
+
3
12
  desc 'Run the test suite'
4
13
  task :test do
14
+ cmd = 'minitest4', 'test'
15
+ cmd = 'minitest4', '-p', 'test', '--', '-v'
16
+
5
17
  #> we need to set RUBYLIB, because the test suite
6
18
  # invokes the application as a separate process
7
19
 
@@ -9,11 +21,11 @@ task :test do
9
21
  {
10
22
  'RUBYLIB' =>
11
23
  (
12
- ENV.fetch('RUBYLIB', '').split(':') +
13
- [File.join(__dir__, 'lib')]
24
+ [File.join(__dir__, 'lib')] +
25
+ ENV.fetch('RUBYLIB', '').split(':')
14
26
  ).join(':')
15
27
  },
16
- FileUtils::RUBY, 'test/absgit_test.rb'
28
+ *with_bundler(*cmd)
17
29
  )
18
30
  end
19
31
 
data/absgit.gemspec CHANGED
@@ -14,8 +14,8 @@ Gem::Specification.new do |spec|
14
14
 
15
15
  spec.description = %q{
16
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.
17
+ manipulate files in a Git repository
18
+ from any location in the filesystem.
19
19
  }.split.join(' ')
20
20
 
21
21
  spec.homepage = "https://github.com/ruafozy/absgit"
data/doc/absgit.md CHANGED
@@ -23,25 +23,25 @@ For example:
23
23
 
24
24
  absgit commit --message blah /some/absolute/path
25
25
 
26
- Its logic is very simple.
26
+ Its logic is simple.
27
27
  It skips over the Git subcommand and iterates
28
28
  over the remaining arguments, looking
29
29
  for the first argument which contains a slash and
30
30
  names a path inside a Git repository.
31
- If it finds such an argument,
31
+ If it finds no such argument, it simply delegates to
32
+ Git.
33
+
34
+ On the other hand, if it *does*
35
+ find such an argument,
32
36
  it infers `GIT_DIR` and `GIT_WORK_TREE`,
33
37
  then invokes `git` with these
34
38
  variables in its environment.
35
39
 
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
40
+ Also,
41
+ any argument which contains a slash and denotes
42
+ a path inside the repository is turned into an
43
+ absolute path before being passed to Git.
44
+ This enables relative paths and symlinks to work.
45
45
 
46
46
  ## Options
47
47
 
@@ -49,7 +49,6 @@ two commands are essentially equivalent:
49
49
 
50
50
  ## Origin of name
51
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".
52
+ ‘abs’ is from ‘absolute’;
53
+ the software is commonly used with
54
+ absolute pathnames.
data/lib/absgit.rb CHANGED
@@ -2,15 +2,17 @@ require 'absgit/version'
2
2
  require 'methadone'
3
3
  require 'optparse'
4
4
  require 'pathname'
5
+ require 'utils'
5
6
 
6
7
  class Absgit
7
8
  include Methadone::CLILogging
9
+ include Utils
8
10
 
9
11
  GIT_DIR_BASE = '.git'
10
12
  PROGRAM_NAME = 'absgit'
11
13
 
12
14
  def initialize(args)
13
- @args = args
15
+ @args = args.dup
14
16
  @options = {}
15
17
  end
16
18
 
@@ -74,25 +76,34 @@ class Absgit
74
76
  break repo if !repo.nil?
75
77
  }
76
78
 
77
- env =
78
- if repo_path.nil?
79
- {}
80
- else
81
- {
82
- 'GIT_DIR' => (repo_path + GIT_DIR_BASE).to_s,
83
- 'GIT_WORK_TREE' => repo_path.to_s,
84
- }
85
- end
79
+ if repo_path.nil?
80
+ env = {}
81
+
82
+ git_args = @args
83
+ else
84
+ env = {
85
+ 'GIT_DIR' => (repo_path + GIT_DIR_BASE).to_s,
86
+ 'GIT_WORK_TREE' => repo_path.to_s,
87
+ }
88
+
89
+ git_args = @args.map { |arg|
90
+ make_tracked_files_relative_to_repo(repo_path, arg)
91
+ }
92
+ end
93
+
94
+ command = ['git'] + git_args
86
95
 
96
+ debug(command.inspect)
97
+ debug(env.inspect)
98
+
99
+ system(env, *command)
100
+ #
87
101
  #< it seems better to use environment variables
88
102
  # rather than "--git-dir" and "--work-tree", because
89
103
  # environment variables will be inherited by processes
90
104
  # spawned by git aliases.
91
105
 
92
- command = ['git'] + @args
93
- debug(command.inspect)
94
- debug(env.inspect)
95
- system(env, *command)
106
+ exit($?.exited? ? $?.exitstatus: 1)
96
107
  end
97
108
  end
98
109
 
@@ -1,3 +1,3 @@
1
1
  class Absgit
2
- VERSION = '0.1.3'
2
+ VERSION = '0.2.1'
3
3
  end
data/lib/utils.rb ADDED
@@ -0,0 +1,30 @@
1
+ module Utils
2
+ private
3
+
4
+ def make_tracked_files_relative_to_repo(repo_dir, x)
5
+ repo_dir_real = Pathname.new(repo_dir).realpath.to_s
6
+
7
+ catch(:finished) do
8
+ if x.include?('/')
9
+ discards = []
10
+
11
+ Pathname.new(x).ascend do |path|
12
+ if path.exist?
13
+ real = path.realpath.to_s
14
+
15
+ if real == repo_dir_real ||
16
+ real.start_with?(repo_dir_real + '/')
17
+ then
18
+ x = File.join(real, *discards)
19
+ throw :finished
20
+ end
21
+ else
22
+ discards.unshift(path.basename)
23
+ end
24
+ end
25
+ end
26
+ end
27
+
28
+ x
29
+ end
30
+ end
@@ -0,0 +1,7 @@
1
+ def with_bundler(*command)
2
+ command.tap do |cmd|
3
+ if !ENV.has_key?('BUNDLE_BIN_PATH')
4
+ cmd.unshift('bundle', 'exec')
5
+ end
6
+ end
7
+ end
data/test/absgit_test.rb CHANGED
@@ -1,16 +1,8 @@
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
1
  require 'absgit'
11
2
  require 'fileutils'
12
3
  require 'shellwords'
13
4
  require 'tmpdir'
5
+ require 'minitest/unit'
14
6
 
15
7
  class AbsgitTest < MiniTest::Unit::TestCase
16
8
  APP_PATH = File.expand_path(
@@ -87,6 +79,46 @@ class AbsgitTest < MiniTest::Unit::TestCase
87
79
  )
88
80
  end
89
81
 
82
+ def test_rel_path_works
83
+ # Given
84
+
85
+ repo = 'repo'
86
+ Dir.mkdir(repo)
87
+ system(*%W{git init --quiet #{repo}})
88
+ filename = 'f'
89
+ rel_path = File.join(repo, filename)
90
+ FileUtils.touch(rel_path)
91
+
92
+ # When
93
+
94
+ system(APP_PATH, 'add', rel_path)
95
+
96
+ # Then
97
+
98
+ assert_equal(1, files_in_index(repo).size)
99
+ end
100
+
101
+ def test_symlink_works
102
+ # Given
103
+
104
+ repo = 'repo'
105
+ Dir.mkdir(repo)
106
+ system(*%W{git init --quiet #{repo}})
107
+ filename = 'f'
108
+ rel_path = File.join(repo, filename)
109
+ FileUtils.touch(rel_path)
110
+ symlink = './symlink'
111
+ File.symlink(rel_path, symlink)
112
+
113
+ # When
114
+
115
+ system(APP_PATH, 'add', symlink)
116
+
117
+ # Then
118
+
119
+ assert_equal(1, files_in_index(repo).size)
120
+ end
121
+
90
122
  def test_commit_does_not_require_chdir_to_repo
91
123
  # Given
92
124
 
@@ -151,8 +183,44 @@ class AbsgitTest < MiniTest::Unit::TestCase
151
183
  assert_equal(num_commits_before + 1, num_commits(repo))
152
184
  end
153
185
 
186
+ class InRepo < self
187
+ def setup
188
+ super
189
+ Dir.chdir(get_repo)
190
+ end
191
+
192
+ def test_exit_status_preserved
193
+ [
194
+ %w{ls-files},
195
+ %w{ls-files --non-existent-option},
196
+ %w{add non-existent-file},
197
+ ].each do |args|
198
+ # Given & When
199
+
200
+ opts = {
201
+ err: '/dev/null',
202
+ out: '/dev/null',
203
+ }
204
+ system(*(%w{git} + args), opts)
205
+ git_exit_status = $?.exitstatus
206
+ system(*([APP_PATH] + args), opts)
207
+ absgit_exit_status = $?.exitstatus
208
+
209
+ # Then
210
+
211
+ assert_equal(git_exit_status, absgit_exit_status)
212
+ end
213
+ end
214
+ end
215
+
154
216
  private
155
217
 
218
+ def files_in_index(repo)
219
+ Dir.chdir(repo) do
220
+ %x{git ls-files}.split("\n")
221
+ end
222
+ end
223
+
156
224
  def num_commits(repo_dir)
157
225
  Dir.chdir(repo_dir) {
158
226
  `git rev-list --count HEAD`.match(/\A\d+\n\z/) { |m|
@@ -160,9 +228,15 @@ class AbsgitTest < MiniTest::Unit::TestCase
160
228
  }
161
229
  }
162
230
  end
231
+
232
+ def get_repo
233
+ dir = Dir.mktmpdir(nil, '.')
234
+ system('git', 'init', '--quiet', dir)
235
+ dir
236
+ end
163
237
  end
164
238
 
165
- if false
239
+ 0.times do
166
240
  module Kernel
167
241
  alias old_system system
168
242
 
@@ -0,0 +1,42 @@
1
+ require 'fileutils'
2
+ require 'minitest/unit'
3
+ require 'tmpdir'
4
+ require 'utils'
5
+
6
+ class UtilsTest < MiniTest::Unit::TestCase
7
+ include Utils
8
+
9
+ def setup
10
+ @saved_dir = Dir.pwd
11
+ @temp_dir = Dir.mktmpdir
12
+ Dir.chdir(@temp_dir)
13
+ end
14
+
15
+ def teardown
16
+ Dir.chdir(@saved_dir)
17
+ FileUtils.rm_r(@temp_dir, secure: true)
18
+ end
19
+
20
+ def test_make_tracked_files_relative_to_repo
21
+ # Given
22
+
23
+ name1 = 'a/b/c/d'
24
+ FileUtils.makedirs(name1)
25
+
26
+ symlink = 'a/b/c/symlink'
27
+ File.symlink('d', symlink)
28
+
29
+ name2 = "#{symlink}/e/f/g/h"
30
+
31
+ # When
32
+
33
+ result = make_tracked_files_relative_to_repo(name1, name2)
34
+
35
+ # Then
36
+
37
+ assert_equal(
38
+ File.join(File.realpath(name1), 'e/f/g/h'),
39
+ result
40
+ )
41
+ end
42
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: absgit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ruafozy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-05-11 00:00:00.000000000 Z
11
+ date: 2013-06-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: methadone
@@ -81,7 +81,7 @@ dependencies:
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
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.
84
+ Git repository from any location in the filesystem.
85
85
  email:
86
86
  executables:
87
87
  - absgit
@@ -99,7 +99,10 @@ files:
99
99
  - doc/absgit.md
100
100
  - lib/absgit.rb
101
101
  - lib/absgit/version.rb
102
+ - lib/utils.rb
103
+ - rakelib/utils.rake
102
104
  - test/absgit_test.rb
105
+ - test/utils_test.rb
103
106
  homepage: https://github.com/ruafozy/absgit
104
107
  licenses:
105
108
  - MIT