dandelion 0.4.17 → 0.5.0

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: 317add4350e3f191268e262e1947f35313f4a13b
4
- data.tar.gz: f8a1ea25badbe77e8723a32a45aef8a22c05be08
3
+ metadata.gz: dfa2a084aedc78ea79f21a41bf1536aca3f1709b
4
+ data.tar.gz: baab9852c5d2adea02a24839e37a40c2234eeb10
5
5
  SHA512:
6
- metadata.gz: 94800c3e6a2b28d747912075c51ca31826ecc6cc5281505fe59420786dd1a4b4f6bc87bfb2cf0807a224e5a34393d84bebe6cf1ccea0eefad39682524f1c24ea
7
- data.tar.gz: 82936f82f49cbc03de7e3881d13cc5f5c5ba168fb66457ba18e50e5e13a710a3cfff5acef811fe0db2d96f18a6908aacc83a4129b1a4103a1ed85857c5d92734
6
+ metadata.gz: 9a6782c6f02a58ea73d9f878d717884bb0143039ca9d0be142ab919095c75e2e181e2c3eeeab49bcefc46c65c1eb671315b00e634b14618d7ef6d906d81f5f14
7
+ data.tar.gz: 6b89c90540d0d5d0d908467528b8636d2a5af0f35cbf462f748e315aec3524b1b8c04698327f96ecddebdab3b8dda99e13e8b95e87727a4f4e6280fbf32a4b95
@@ -9,6 +9,9 @@ module Dandelion
9
9
 
10
10
  def delete(path)
11
11
  end
12
+
13
+ def symlink(path, data)
14
+ end
12
15
  end
13
16
  end
14
17
  end
@@ -55,6 +55,19 @@ module Dandelion
55
55
  end
56
56
  end
57
57
 
58
+ def symlink(file, target)
59
+ begin
60
+ @sftp.symlink!(target, path(file))
61
+ rescue Net::SFTP::StatusException => e
62
+ if e.code == 2
63
+ mkdir_p(File.dirname(path(file)))
64
+ else
65
+ @sftp.remove!(path(file))
66
+ end
67
+ @sftp.symlink!(target, path(file))
68
+ end
69
+ end
70
+
58
71
  def to_s
59
72
  "sftp://#{@config['username']}@#{@config['host']}/#{@config['path']}"
60
73
  end
@@ -12,4 +12,4 @@ module Dandelion
12
12
  @read.() if @read
13
13
  end
14
14
  end
15
- end
15
+ end
@@ -25,7 +25,12 @@ module Dandelion
25
25
  yield Change.new(path, change.type)
26
26
  else
27
27
  read = -> { @tree.data(change.path) }
28
- yield Change.new(path, change.type, read)
28
+
29
+ if @tree.is_symlink?(change.path)
30
+ yield Change.new(path, :symlink, read)
31
+ else
32
+ yield Change.new(path, change.type, read)
33
+ end
29
34
  end
30
35
  end
31
36
  end
@@ -50,6 +50,13 @@ module Dandelion
50
50
  when :delete
51
51
  log.debug("Deleting file: #{change.path}")
52
52
  @adapter.delete(change.path)
53
+ when :symlink
54
+ if @adapter.respond_to?(:symlink)
55
+ log.debug("Creating symlink: #{change.path}")
56
+ @adapter.symlink(change.path, change.data)
57
+ else
58
+ log.debug("Skipped creating symlink: #{change.path} -> #{change.data}")
59
+ end
53
60
  end
54
61
  end
55
62
 
@@ -7,6 +7,11 @@ module Dandelion
7
7
  @commit = commit
8
8
  end
9
9
 
10
+ def is_symlink?(path)
11
+ # https://github.com/libgit2/libgit2/blob/development/include/git2/types.h
12
+ @commit.tree.path(path)[:filemode] == 0120000
13
+ end
14
+
10
15
  def data(path)
11
16
  submodule = @repo.submodules[path]
12
17
 
@@ -15,48 +20,21 @@ module Dandelion
15
20
  nil
16
21
  else
17
22
  info, obj = object(path)
18
- content(info, obj)
23
+ blob_content(obj)
19
24
  end
20
25
  end
21
26
 
22
27
  private
23
28
 
24
29
  def object(path)
25
- object = @commit.tree
26
- info = {}
27
-
28
- path.split('/').each do |name|
29
- info = object[name]
30
- return nil unless info
31
- return nil unless info[:type]
32
-
33
- object = @repo.lookup(info[:oid])
34
-
35
- return nil unless object
36
- end
37
-
30
+ info = @commit.tree.path(path)
31
+ object = @repo.lookup(info[:oid])
38
32
  [info, object]
39
33
  end
40
34
 
41
- def content(info, object)
42
- # https://github.com/libgit2/libgit2/blob/development/include/git2/types.h
43
- if info[:filemode] == 0120000
44
- symlink_content(object)
45
- else
46
- blob_content(object)
47
- end
48
- end
49
-
50
35
  def blob_content(object)
51
36
  object.read_raw.data
52
37
  end
53
38
 
54
- def symlink_content(object)
55
- path = object.read_raw.data
56
-
57
- result = data(path)
58
- result ||= IO.binread(path) # external link
59
- result
60
- end
61
39
  end
62
40
  end
@@ -1,3 +1,3 @@
1
1
  module Dandelion
2
- VERSION = '0.4.17'
2
+ VERSION = '0.5.0'
3
3
  end
@@ -70,4 +70,30 @@ describe Dandelion::Changeset do
70
70
  end
71
71
  end
72
72
  end
73
+
74
+ context 'diff adds symlink' do
75
+ let(:changeset) { test_changeset_with_symlinks }
76
+
77
+ describe '#enumerable' do
78
+ let(:changes) { changeset.to_a }
79
+
80
+ it 'returns all changes' do
81
+ expect(changes).to be_a(Array)
82
+ expect(changes.length).to eq 1
83
+ expect(changes.map(&:path)).to eq ['link']
84
+ expect(changes.map(&:type)).to eq [:symlink]
85
+ end
86
+
87
+ it 'returns data for write changes' do
88
+ expect(changes.select { |c| c.type != :delete }.map(&:data)).to eq ["baz/bar"]
89
+ end
90
+ end
91
+
92
+ describe '#empty?' do
93
+ it 'returns false' do
94
+ expect(changeset.empty?).to eq false
95
+ end
96
+ end
97
+ end
98
+
73
99
  end
@@ -16,8 +16,8 @@ describe Dandelion::Tree do
16
16
  let(:repo) { test_repo('repo_symlink') }
17
17
  let(:tree) { test_tree(repo: repo, commit: repo.lookup('4c19bbe7ba04230a0ae2281c1abbc48a76a66550')) }
18
18
 
19
- it 'returns content of link source path' do
20
- expect(tree.data('link')).to eq "bar\n"
19
+ it 'returns target path of the symlink' do
20
+ expect(tree.data('link')).to eq "baz/bar"
21
21
  end
22
22
  end
23
23
 
@@ -27,6 +27,14 @@ def test_changeset(options = {})
27
27
  Dandelion::Changeset.new(test_tree, test_commits.first, options)
28
28
  end
29
29
 
30
+ def test_changeset_with_symlinks(options = {})
31
+ repo = test_repo('repo_symlink')
32
+ commit0 = repo.lookup('3d9b743acb4a84dd99002d2c6f3fcf1a47e9f06b')
33
+ commit1 = repo.lookup('4c19bbe7ba04230a0ae2281c1abbc48a76a66550')
34
+ tree = test_tree(repo: repo, commit: commit1)
35
+ Dandelion::Changeset.new(tree, commit0, options)
36
+ end
37
+
30
38
  def test_diff
31
39
  test_changeset.diff
32
40
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dandelion
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.17
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Nelson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-20 00:00:00.000000000 Z
11
+ date: 2016-07-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rugged