clone_git_file 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a6a43dd0a36bfccd6e5c32722a835ecc6ceeac55
4
- data.tar.gz: d1fd69615798975cc626c7a135e25d802d75a437
3
+ metadata.gz: 13bae9e061bbabf4bfaca08c32fdc35076cda098
4
+ data.tar.gz: 0b6bddb75912059517b079d27a50e93df2c3e5ec
5
5
  SHA512:
6
- metadata.gz: 0ab9272637734ae7ae03b0ab59bf19914308af732378ab0f30f6f47ba2b959840121627af3da9d53b050b60d5fd6d6a94eb14f5558957e04013351bea58f2872
7
- data.tar.gz: 93cbe3fa002925024e92131bdafbf18feae483e1587fbcedf15d72bbb2b64b0b04dacca4141d0dd393564a413db941b70036c548492b35c2d42ea5d342116fd3
6
+ metadata.gz: 8f79061cbdb9b1da10d2027a43ad85a54a0ef25021b58fcf255215c040174403576cab6d6a755c4af66d4c5f43bbb7f6ea706797f7c4187a81f6e072ca81fc37
7
+ data.tar.gz: 1967c924a6a7a68e4c667f32153462c4bcc9d8d668c8bc1222239d36262150aa221c333e6e37a28a8bbc0a121c96a878327495e01ce62dc6d33a6abf6cc98d98
data/README.md CHANGED
@@ -60,18 +60,29 @@ EDITOR=mvim TARGET_DIRECTORY=~/dev clone_git_file https://github.com/brandoncc/c
60
60
  ### Bonus
61
61
 
62
62
  * You can also supply the repo url or a repo subdirectory url, and that directory will be opened by your editor.
63
- * Setup an alias to make using the gem easy. For example, here are mine (zsh):
63
+ * Setup an alias and/or function to make using the gem easy. For example, here are mine (zsh):
64
64
 
65
65
  ```bash
66
66
  alias cgf="TARGET_DIRECTORY=~/dev EDITOR=mvim clone_git_file $1"
67
- alias ogf="TARGET_DIRECTORY=~/dev EDITOR=mvim clone_git_file -ts $1"
67
+
68
+ function ogf () {
69
+ echo "Cloning, your editor will open when clone has completed..."
70
+ source <(TARGET_DIRECTORY=~/dev EDITOR=mvim clone_git_file -ts $1)
71
+ }
68
72
  ```
69
73
 
70
- `cgf` clones, then prints a message with the location of the cloned file/directory.
74
+ `cgf` clones, then prints a message with the location of the cloned
75
+ file/directory.
71
76
 
72
- `ogf` prints the commands to open the file/directory in my editor. I then use `source <(...)` to pipe the printed command to `source` which runs it in my current shell. This fixes some weird things that happen when opening the editor in a child process, and also allows the current directory of my current shell to be changed (instead of the child process shell which will be lost when you close the editor).
77
+ `ogf` prints the commands to open the file/directory in my editor. I then
78
+ use `source <(...)` to pipe the printed command to `source` which runs it
79
+ in my current shell. This fixes some weird things that happen when opening
80
+ the editor in a child process, and also allows the current directory of my
81
+ current shell to be changed (instead of the child process shell which will
82
+ be lost when you close the editor).
73
83
 
74
- Unfortunately `$1` doesn't get passed into the nested command, so the `source <()` usage can't be in the alias (still looking for a solution to this if anybody has one), so I used TextExpander to setup a snippet which handles that part, with the final command I run being `source <(ogf https://github.com/brandoncc/clone_git_file/blob/master/README.md)`.
84
+ `ogf` has to be a function so that `$1` will expand properly. If you use an
85
+ alias instead, `$1` doesn't hold the correct value in the nested command.
75
86
 
76
87
  # Limitations
77
88
 
data/Rakefile CHANGED
@@ -1,10 +1,7 @@
1
1
  require "bundler/gem_tasks"
2
- require "rake/testtask"
2
+ require "rspec/core/rake_task"
3
3
 
4
- Rake::TestTask.new(:test) do |t|
5
- t.libs << "test"
6
- t.libs << "lib"
7
- t.test_files = FileList['test/**/*_test.rb']
8
- end
4
+ RSpec::Core::RakeTask.new
9
5
 
10
- task :default => :test
6
+ task :default => :spec
7
+ task :test => :spec
@@ -21,14 +21,13 @@ Gem::Specification.new do |spec|
21
21
  raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
22
22
  end
23
23
 
24
- spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec|features)/}) }
25
25
  spec.bindir = "exe"
26
26
  spec.executables = ["clone_git_file"]
27
27
  spec.require_paths = ["lib"]
28
28
 
29
29
  spec.add_development_dependency "bundler", "~> 1.10"
30
30
  spec.add_development_dependency "rake", "~> 10.0"
31
- spec.add_development_dependency "minitest"
32
- spec.add_development_dependency "minitest-spec-context"
33
- spec.add_development_dependency "mocha"
31
+ spec.add_development_dependency "pry"
32
+ spec.add_development_dependency "rspec", "~> 3.4.0"
34
33
  end
@@ -4,7 +4,7 @@ require "clone_git_file/github_repo_parser"
4
4
  module CloneGitFile
5
5
  class Cloner
6
6
  def initialize(file, options = {})
7
- @file = file
7
+ @file = file.gsub("%20", " ")
8
8
  @options = options
9
9
  end
10
10
 
@@ -35,11 +35,16 @@ module CloneGitFile
35
35
 
36
36
  def launch_editor
37
37
  commands = ""
38
- file_path = "#{local_repo_path}/#{parsed_data.file_relative_path}"
38
+ file_path = "#{local_repo_path}"
39
+ file_path << "/#{parsed_data.file_relative_path}" if parsed_data.file_relative_path
39
40
 
40
41
  # change into the directory so that relative file loads will work
41
- commands << "cd #{File.dirname(file_path)}"
42
- commands << "\n#{ENV["EDITOR"]} #{file_path}"
42
+ if File.directory?(file_path)
43
+ commands << "cd #{file_path}"
44
+ else
45
+ commands << "cd #{File.dirname(file_path)}"
46
+ end
47
+ commands << %(\n#{ENV["EDITOR"]} "#{file_path}")
43
48
 
44
49
  if @options[:output_run_command_to_terminal]
45
50
  puts(commands)
@@ -49,14 +54,18 @@ module CloneGitFile
49
54
  end
50
55
 
51
56
  def print_clone_location
52
- puts "Cloned to: #{local_repo_path}/#{parsed_data.file_relative_path}"
57
+ clone_path = "#{local_repo_path}"
58
+ clone_path << "/#{parsed_data.file_relative_path}" if parsed_data.file_relative_path
59
+
60
+ puts "Cloned to: #{clone_path}"
53
61
  end
54
62
 
55
63
  def clone_repo
56
64
  commands = ""
57
65
  commands << "git clone #{parsed_data.repo_url} #{local_repo_path}"
58
66
 
59
- if parsed_data.branch_name
67
+ branch_name = parsed_data.branch_name
68
+ if branch_name && branch_name != ""
60
69
  commands << "\ncd #{local_repo_path}"
61
70
  commands << "\ngit checkout #{parsed_data.branch_name}"
62
71
  end
@@ -36,10 +36,11 @@ module CloneGitFile
36
36
  end
37
37
 
38
38
  def parse_file_relative_path
39
- path = @file.match(%r{#{Regexp.escape(parse_repo_url)}/(.+)$})[1]
39
+ path = @file.match(%r{#{Regexp.escape(parse_repo_url)}/(.+)$})
40
+ path = path.nil? ? "" : path[1]
40
41
  path.sub!(%r{^(?:blob|tree)/[^/]+}, '') if has_branch?
41
42
  path.sub!(%r{^/}, '')
42
- path
43
+ path == "" ? nil : path
43
44
  rescue NoMethodError
44
45
  ''
45
46
  end
@@ -1,3 +1,3 @@
1
1
  module CloneGitFile
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.6"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clone_git_file
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Conway
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-12-19 00:00:00.000000000 Z
11
+ date: 2016-01-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -39,7 +39,7 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: minitest
42
+ name: pry
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
@@ -53,33 +53,19 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: minitest-spec-context
56
+ name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
- - !ruby/object:Gem::Dependency
70
- name: mocha
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
59
+ - - "~>"
74
60
  - !ruby/object:Gem::Version
75
- version: '0'
61
+ version: 3.4.0
76
62
  type: :development
77
63
  prerelease: false
78
64
  version_requirements: !ruby/object:Gem::Requirement
79
65
  requirements:
80
- - - ">="
66
+ - - "~>"
81
67
  - !ruby/object:Gem::Version
82
- version: '0'
68
+ version: 3.4.0
83
69
  description:
84
70
  email:
85
71
  - brandoncc@gmail.com