gitlab-gollum-lib 1.1.0 → 4.2.7

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.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -3
  3. data/HISTORY.md +25 -0
  4. data/LICENSE +1 -1
  5. data/README.md +24 -312
  6. data/Rakefile +32 -16
  7. data/gemspec.rb +110 -0
  8. data/gollum-lib.gemspec +8 -75
  9. data/gollum-lib_java.gemspec +4 -0
  10. data/lib/gollum-lib.rb +18 -6
  11. data/lib/gollum-lib/blob_entry.rb +10 -9
  12. data/lib/gollum-lib/committer.rb +37 -30
  13. data/lib/gollum-lib/file.rb +71 -15
  14. data/lib/gollum-lib/file_view.rb +53 -48
  15. data/lib/gollum-lib/filter.rb +78 -0
  16. data/lib/gollum-lib/filter/code.rb +145 -0
  17. data/lib/gollum-lib/filter/emoji.rb +39 -0
  18. data/lib/gollum-lib/filter/macro.rb +57 -0
  19. data/lib/gollum-lib/filter/metadata.rb +29 -0
  20. data/lib/gollum-lib/filter/plain_text.rb +16 -0
  21. data/lib/gollum-lib/filter/plantuml.rb +176 -0
  22. data/lib/gollum-lib/filter/remote_code.rb +63 -0
  23. data/lib/gollum-lib/filter/render.rb +20 -0
  24. data/lib/gollum-lib/filter/sanitize.rb +18 -0
  25. data/lib/gollum-lib/filter/tags.rb +327 -0
  26. data/lib/gollum-lib/filter/toc.rb +134 -0
  27. data/lib/gollum-lib/filter/wsd.rb +54 -0
  28. data/lib/gollum-lib/git_access.rb +30 -32
  29. data/lib/gollum-lib/gitcode.rb +16 -16
  30. data/lib/gollum-lib/helpers.rb +3 -3
  31. data/lib/gollum-lib/hook.rb +35 -0
  32. data/lib/gollum-lib/macro.rb +43 -0
  33. data/lib/gollum-lib/macro/all_pages.rb +11 -0
  34. data/lib/gollum-lib/macro/global_toc.rb +12 -0
  35. data/lib/gollum-lib/macro/navigation.rb +20 -0
  36. data/lib/gollum-lib/macro/series.rb +48 -0
  37. data/lib/gollum-lib/markup.rb +95 -572
  38. data/lib/gollum-lib/markups.rb +9 -3
  39. data/lib/gollum-lib/page.rb +109 -80
  40. data/lib/gollum-lib/pagination.rb +1 -1
  41. data/lib/gollum-lib/sanitization.rb +75 -75
  42. data/lib/gollum-lib/version.rb +5 -0
  43. data/lib/gollum-lib/wiki.rb +287 -129
  44. metadata +237 -92
  45. data/CHANGELOG +0 -2
  46. data/VERSION +0 -1
  47. data/lib/gollum-lib/grit_ext.rb +0 -20
  48. data/lib/gollum-lib/remote_code.rb +0 -39
  49. data/lib/gollum-lib/web_sequence_diagram.rb +0 -44
data/Rakefile CHANGED
@@ -9,11 +9,11 @@ require 'date'
9
9
  #############################################################################
10
10
 
11
11
  def name
12
- @name ||= Dir['*.gemspec'].first.split('.').first
12
+ "gollum-lib"
13
13
  end
14
14
 
15
15
  def version
16
- line = File.read("lib/#{name}.rb")[/^\s*VERSION\s*=\s*.*/]
16
+ line = File.read("lib/gollum-lib/version.rb")[/^\s*VERSION\s*=\s*.*/]
17
17
  line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
18
18
  end
19
19
 
@@ -27,13 +27,13 @@ def next_version
27
27
  end
28
28
 
29
29
  def bump_version
30
- old_file = File.read("lib/#{name}.rb")
30
+ old_file = File.read("lib/gollum-lib/version.rb")
31
31
  old_version_line = old_file[/^\s*VERSION\s*=\s*.*/]
32
32
  new_version = next_version
33
- # replace first match of old vesion with new version
34
- old_file.sub!(old_version_line, " VERSION = '#{new_version}'")
33
+ # replace first match of old version with new version
34
+ old_file.sub!(old_version_line, " VERSION = '#{new_version}'")
35
35
 
36
- File.write("lib/#{name}.rb", old_file)
36
+ File.write("lib/gollum-lib/version.rb", old_file)
37
37
 
38
38
  new_version
39
39
  end
@@ -47,11 +47,15 @@ def rubyforge_project
47
47
  end
48
48
 
49
49
  def gemspec_file
50
- "#{name}.gemspec"
50
+ "gemspec.rb"
51
51
  end
52
52
 
53
- def gem_file
54
- "#{name}-#{version}.gem"
53
+ def gemspecs
54
+ ["#{name}.gemspec", "#{name}_java.gemspec"]
55
+ end
56
+
57
+ def gem_files
58
+ ["#{name}-#{version}.gem", "#{name}-#{version}-java.gem"]
55
59
  end
56
60
 
57
61
  def replace_header(head, header_name)
@@ -101,6 +105,11 @@ task :bump do
101
105
  Rake::Task[:validate].execute
102
106
  end
103
107
 
108
+ desc "Build and install"
109
+ task :install => :build do
110
+ sh "gem install --local --no-ri --no-rdoc pkg/#{name}-#{version}.gem"
111
+ end
112
+
104
113
  #############################################################################
105
114
  #
106
115
  # Packaging tasks
@@ -114,29 +123,36 @@ task :release => :build do
114
123
  exit!
115
124
  end
116
125
  sh "git commit --allow-empty -a -m 'Release #{version}'"
117
- sh "git pull"
126
+ sh "git pull --rebase origin master"
118
127
  sh "git tag v#{version}"
119
128
  sh "git push origin master"
120
129
  sh "git push origin v#{version}"
121
130
  sh "gem push pkg/#{name}-#{version}.gem"
131
+ sh "gem push pkg/#{name}-#{version}-java.gem"
122
132
  end
123
133
 
134
+ desc 'Publish to rubygems. Same as release'
135
+ task :publish => :release
136
+
124
137
  desc 'Build gem'
125
138
  task :build => :gemspec do
126
139
  sh "mkdir -p pkg"
127
- sh "gem build #{gemspec_file}"
128
- sh "mv #{gem_file} pkg"
140
+ gemspecs.each do |gemspec|
141
+ sh "gem build #{gemspec}"
142
+ end
143
+ gem_files.each do |gem_file|
144
+ sh "mv #{gem_file} pkg"
145
+ end
129
146
  end
130
147
 
131
148
  desc 'Update gemspec'
132
149
  task :gemspec => :validate do
133
150
  # read spec file and split out manifest section
134
151
  spec = File.read(gemspec_file)
135
- head, manifest, tail = spec.split(" # = MANIFEST =\n")
152
+ head, _manifest, tail = spec.split(" # = MANIFEST =\n")
136
153
 
137
154
  # replace name version and date
138
155
  replace_header(head, :name)
139
- replace_header(head, :version)
140
156
  replace_header(head, :date)
141
157
  #comment this out if your rubyforge_project has a different name
142
158
  replace_header(head, :rubyforge_project)
@@ -146,12 +162,12 @@ task :gemspec => :validate do
146
162
  split("\n").
147
163
  sort.
148
164
  reject { |file| file =~ /^\./ }.
149
- reject { |file| file =~ /^(rdoc|pkg|test|Home\.md|\.gitattributes)/ }.
165
+ reject { |file| file =~ /^(rdoc|pkg|test|Home\.md|\.gitattributes|Guardfile)/ }.
150
166
  map { |file| " #{file}" }.
151
167
  join("\n")
152
168
 
153
169
  # piece file back together and write
154
- manifest = " s.files = %w[\n#{files}\n ]\n"
170
+ manifest = " s.files = %w(\n#{files}\n )\n"
155
171
  spec = [head, manifest, tail].join(" # = MANIFEST =\n")
156
172
  File.open(gemspec_file, 'w') { |io| io.write(spec) }
157
173
  puts "Updated #{gemspec_file}"
data/gemspec.rb ADDED
@@ -0,0 +1,110 @@
1
+ def specification(version, default_adapter, platform = nil)
2
+ Proc.new do |s|
3
+ s.specification_version = 2 if s.respond_to? :specification_version=
4
+ s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
5
+ s.rubygems_version = '0.0.1'
6
+ s.required_ruby_version = '>= 1.9'
7
+
8
+ s.name = 'gitlab-gollum-lib'
9
+ s.version = version
10
+ s.platform = platform if platform
11
+ s.date = '2017-07-31'
12
+ s.license = 'MIT'
13
+
14
+ s.summary = 'A simple, Git-powered wiki.'
15
+ s.description = 'A simple, Git-powered wiki with a sweet API and local frontend.'
16
+
17
+ s.authors = ['Tom Preston-Werner', 'Rick Olson']
18
+ s.email = 'dmitriy.zaporozhets@gmail.com'
19
+ s.homepage = 'https://gitlab.com/gitlab-org/gollum-lib'
20
+
21
+ s.require_paths = %w(lib)
22
+
23
+ s.rdoc_options = ['--charset=UTF-8']
24
+ s.extra_rdoc_files = %w(README.md LICENSE)
25
+
26
+ s.add_dependency *default_adapter
27
+ s.add_dependency 'rouge', '~> 2.1'
28
+ if RUBY_VERSION < '2.1'
29
+ s.add_dependency 'nokogiri', '~> 1.6.1'
30
+ else
31
+ s.add_dependency 'nokogiri', '>= 1.6.1', '< 2.0'
32
+ end
33
+ s.add_dependency 'stringex', '~> 2.6'
34
+ s.add_dependency 'sanitize', '~> 2.1'
35
+ s.add_dependency 'github-markup', '~> 1.6'
36
+ s.add_dependency 'gemojione', '~> 3.2'
37
+
38
+ s.add_development_dependency 'org-ruby', '~> 0.9.9'
39
+ s.add_development_dependency 'kramdown', '~> 1.6.0'
40
+ s.add_development_dependency 'RedCloth', '~> 4.2.9'
41
+ s.add_development_dependency 'mocha', '~> 1.1.0'
42
+ s.add_development_dependency 'shoulda', '~> 3.5.0'
43
+ s.add_development_dependency 'wikicloth', '~> 0.8.3'
44
+ s.add_development_dependency 'rake', '~> 10.4.0'
45
+ s.add_development_dependency 'pry', '~> 0.10.1'
46
+ # required by pry
47
+ s.add_development_dependency 'rb-readline', '~> 0.5.1'
48
+ # updating minitest-reporters requires a new minitest which fails with gollum's tests.
49
+ s.add_development_dependency 'test-unit', '~> 3.1.5'
50
+ s.add_development_dependency 'minitest-reporters', '~> 0.14.16'
51
+ s.add_development_dependency 'nokogiri-diff', '~> 0.2.0'
52
+ # required by guard
53
+ s.add_development_dependency 'guard', '~> 2.8.2'
54
+ s.add_development_dependency 'guard-minitest', '~> 2.3.2'
55
+ s.add_development_dependency 'rb-inotify', '~> 0.9.3'
56
+ s.add_development_dependency 'rb-fsevent', '~> 0.9.4'
57
+ s.add_development_dependency 'rb-fchange', '~> 0.0.6'
58
+ s.add_development_dependency 'twitter_cldr', '~> 3.1.0'
59
+ # = MANIFEST =
60
+ s.files = %w(
61
+ Gemfile
62
+ HISTORY.md
63
+ LICENSE
64
+ README.md
65
+ Rakefile
66
+ docs/sanitization.md
67
+ gemspec.rb
68
+ gollum-lib.gemspec
69
+ gollum-lib_java.gemspec
70
+ lib/gollum-lib.rb
71
+ lib/gollum-lib/blob_entry.rb
72
+ lib/gollum-lib/committer.rb
73
+ lib/gollum-lib/file.rb
74
+ lib/gollum-lib/file_view.rb
75
+ lib/gollum-lib/filter.rb
76
+ lib/gollum-lib/filter/code.rb
77
+ lib/gollum-lib/filter/emoji.rb
78
+ lib/gollum-lib/filter/macro.rb
79
+ lib/gollum-lib/filter/metadata.rb
80
+ lib/gollum-lib/filter/plain_text.rb
81
+ lib/gollum-lib/filter/plantuml.rb
82
+ lib/gollum-lib/filter/remote_code.rb
83
+ lib/gollum-lib/filter/render.rb
84
+ lib/gollum-lib/filter/sanitize.rb
85
+ lib/gollum-lib/filter/tags.rb
86
+ lib/gollum-lib/filter/toc.rb
87
+ lib/gollum-lib/filter/wsd.rb
88
+ lib/gollum-lib/git_access.rb
89
+ lib/gollum-lib/gitcode.rb
90
+ lib/gollum-lib/helpers.rb
91
+ lib/gollum-lib/hook.rb
92
+ lib/gollum-lib/macro.rb
93
+ lib/gollum-lib/macro/all_pages.rb
94
+ lib/gollum-lib/macro/global_toc.rb
95
+ lib/gollum-lib/macro/navigation.rb
96
+ lib/gollum-lib/macro/series.rb
97
+ lib/gollum-lib/markup.rb
98
+ lib/gollum-lib/markups.rb
99
+ lib/gollum-lib/page.rb
100
+ lib/gollum-lib/pagination.rb
101
+ lib/gollum-lib/sanitization.rb
102
+ lib/gollum-lib/version.rb
103
+ lib/gollum-lib/wiki.rb
104
+ licenses/licenses.txt
105
+ )
106
+ # = MANIFEST =
107
+
108
+ s.test_files = s.files.select { |path| path =~ /^test\/test_.*\.rb/ }
109
+ end
110
+ end
data/gollum-lib.gemspec CHANGED
@@ -1,75 +1,8 @@
1
- Gem::Specification.new do |s|
2
- s.specification_version = 2 if s.respond_to? :specification_version=
3
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
4
- s.rubygems_version = '0.0.1'
5
- s.required_ruby_version = ">= 1.8.7"
6
-
7
- s.name = 'gitlab-gollum-lib'
8
- s.version = `cat VERSION`
9
- s.date = Time.now.strftime("%Y-%m-%d")
10
- s.rubyforge_project = 'gollum-lib'
11
-
12
- s.summary = "A simple, Git-powered wiki."
13
- s.description = "A simple, Git-powered wiki with a sweet API and local frontend."
14
-
15
- s.authors = ["Tom Preston-Werner", "Rick Olson"]
16
- s.email = 'tom@github.com'
17
- s.homepage = 'http://github.com/gollum/gollum-lib'
18
-
19
- s.require_paths = %w[lib]
20
-
21
- s.rdoc_options = ["--charset=UTF-8"]
22
- s.extra_rdoc_files = %w[README.md LICENSE]
23
-
24
- s.add_dependency('gitlab-grit', '~> 2.6.1')
25
- s.add_dependency('github-markup', ['>= 0.7.5', '< 1.0.0'])
26
- s.add_dependency('github-markdown', '~> 0.5.3')
27
- s.add_dependency('sanitize', '~> 2.0.3')
28
- s.add_dependency('nokogiri', '~> 1.5.9')
29
- s.add_dependency('stringex', '~> 1.5.1')
30
-
31
- s.add_development_dependency('RedCloth', '~> 4.2.9')
32
- s.add_development_dependency('mocha', '~> 0.13.2')
33
- s.add_development_dependency('org-ruby', '~> 0.8.1')
34
- s.add_development_dependency('shoulda', '~> 3.4.0')
35
- s.add_development_dependency('wikicloth', '~> 0.8.0')
36
- s.add_development_dependency('rake', '~> 10.0.3')
37
- s.add_development_dependency('pry', '~> 0.9.12')
38
- # required by pry
39
- s.add_development_dependency('rb-readline', '~> 0.4.2')
40
- s.add_development_dependency 'minitest-reporters', '~> 0.14.10'
41
- s.add_development_dependency('nokogiri-diff', '~> 0.1.2')
42
-
43
- # = MANIFEST =
44
- s.files = %w[
45
- VERSION
46
- Gemfile
47
- CHANGELOG
48
- LICENSE
49
- README.md
50
- Rakefile
51
- docs/sanitization.md
52
- gollum-lib.gemspec
53
- lib/gollum-lib.rb
54
- lib/gollum-lib/blob_entry.rb
55
- lib/gollum-lib/committer.rb
56
- lib/gollum-lib/file.rb
57
- lib/gollum-lib/file_view.rb
58
- lib/gollum-lib/git_access.rb
59
- lib/gollum-lib/gitcode.rb
60
- lib/gollum-lib/grit_ext.rb
61
- lib/gollum-lib/helpers.rb
62
- lib/gollum-lib/markup.rb
63
- lib/gollum-lib/markups.rb
64
- lib/gollum-lib/page.rb
65
- lib/gollum-lib/pagination.rb
66
- lib/gollum-lib/remote_code.rb
67
- lib/gollum-lib/sanitization.rb
68
- lib/gollum-lib/web_sequence_diagram.rb
69
- lib/gollum-lib/wiki.rb
70
- licenses/licenses.txt
71
- ]
72
- # = MANIFEST =
73
-
74
- s.test_files = s.files.select { |path| path =~ /^test\/test_.*\.rb/ }
75
- end
1
+ require File.join(File.dirname(__FILE__), 'gemspec.rb')
2
+ require File.join(File.dirname(__FILE__), 'lib', 'gollum-lib', 'version.rb')
3
+ if RUBY_PLATFORM == 'java' then
4
+ default_adapter = ['gollum-rjgit_adapter', '~> 0.3']
5
+ else
6
+ default_adapter = ['gollum-grit_adapter', '~> 1.0']
7
+ end
8
+ Gem::Specification.new &specification(Gollum::Lib::VERSION, default_adapter)
@@ -0,0 +1,4 @@
1
+ require File.join(File.dirname(__FILE__), 'gemspec.rb')
2
+ require File.join(File.dirname(__FILE__), 'lib', 'gollum-lib', 'version.rb')
3
+ default_adapter = ['gollum-rjgit_adapter', '~> 0.3']
4
+ Gem::Specification.new &specification(Gollum::Lib::VERSION, default_adapter, "java")
data/lib/gollum-lib.rb CHANGED
@@ -3,33 +3,42 @@
3
3
  require 'digest/md5'
4
4
  require 'digest/sha1'
5
5
  require 'ostruct'
6
+ require 'pathname'
7
+
8
+ DEFAULT_ADAPTER = RUBY_PLATFORM == 'java' ? 'rjgit_adapter' : 'grit_adapter'
9
+
10
+ if defined?(Gollum::GIT_ADAPTER)
11
+ require "#{Gollum::GIT_ADAPTER.downcase}_adapter"
12
+ else
13
+ require DEFAULT_ADAPTER
14
+ end
6
15
 
7
16
  # external
8
- require 'grit'
9
- require File.expand_path('../gollum-lib/grit_ext', __FILE__)
10
17
  require 'github/markup'
11
18
  require 'sanitize'
19
+ require 'gemojione'
12
20
 
13
21
  # internal
14
22
  require File.expand_path('../gollum-lib/git_access', __FILE__)
23
+ require File.expand_path('../gollum-lib/hook', __FILE__)
15
24
  require File.expand_path('../gollum-lib/committer', __FILE__)
16
25
  require File.expand_path('../gollum-lib/pagination', __FILE__)
17
26
  require File.expand_path('../gollum-lib/blob_entry', __FILE__)
18
27
  require File.expand_path('../gollum-lib/wiki', __FILE__)
19
28
  require File.expand_path('../gollum-lib/page', __FILE__)
29
+ require File.expand_path('../gollum-lib/macro', __FILE__)
20
30
  require File.expand_path('../gollum-lib/file', __FILE__)
21
31
  require File.expand_path('../gollum-lib/file_view', __FILE__)
22
32
  require File.expand_path('../gollum-lib/markup', __FILE__)
23
33
  require File.expand_path('../gollum-lib/markups', __FILE__)
24
34
  require File.expand_path('../gollum-lib/sanitization', __FILE__)
25
- require File.expand_path('../gollum-lib/web_sequence_diagram', __FILE__)
35
+ require File.expand_path('../gollum-lib/filter', __FILE__)
26
36
 
27
37
  # Set ruby to UTF-8 mode
28
38
  # This is required for Ruby 1.8.7 which gollum still supports.
29
- $KCODE = 'U' if RUBY_VERSION[0,3] == '1.8'
39
+ $KCODE = 'U' if RUBY_VERSION[0, 3] == '1.8'
30
40
 
31
41
  module Gollum
32
- VERSION = '1.0.0'
33
42
 
34
43
  def self.assets_path
35
44
  ::File.expand_path('gollum/frontend/public', ::File.dirname(__FILE__))
@@ -49,5 +58,8 @@ module Gollum
49
58
  super(message || "Cannot write #{@dir}/#{@attempted_path}, found #{@dir}/#{@existing_path}.")
50
59
  end
51
60
  end
52
- end
53
61
 
62
+ class InvalidGitRepositoryError < StandardError; end
63
+ class NoSuchPathError < StandardError; end
64
+
65
+ end
@@ -31,14 +31,14 @@ module Gollum
31
31
  @name ||= ::File.basename(@path)
32
32
  end
33
33
 
34
- # Gets a Grit::Blob instance for this blob.
34
+ # Gets a Gollum::Git::Blob instance for this blob.
35
35
  #
36
- # repo - Grit::Repo instance for the Grit::Blob.
36
+ # repo - Gollum::Git::Repo instance for the Gollum::Git::Blob.
37
37
  #
38
- # Returns an unbaked Grit::Blob instance.
38
+ # Returns an unbaked Gollum::Git::Blob instance.
39
39
  def blob(repo)
40
- @blob ||= Grit::Blob.create(repo,
41
- :id => @sha, :name => name, :size => @size, :mode => @mode)
40
+ @blob ||= Gollum::Git::Blob.create(repo,
41
+ :id => @sha, :name => name, :size => @size, :mode => @mode)
42
42
  end
43
43
 
44
44
  # Gets a Page instance for this blob.
@@ -47,8 +47,8 @@ module Gollum
47
47
  #
48
48
  # Returns a Gollum::Page instance.
49
49
  def page(wiki, commit)
50
- blob = self.blob(wiki.repo)
51
- page = wiki.page_class.new(wiki).populate(blob, self.dir)
50
+ blob = self.blob(wiki.repo)
51
+ page = wiki.page_class.new(wiki).populate(blob, self.dir)
52
52
  page.version = commit
53
53
  page
54
54
  end
@@ -59,8 +59,8 @@ module Gollum
59
59
  #
60
60
  # Returns a Gollum::File instance.
61
61
  def file(wiki, commit)
62
- blob = self.blob(wiki.repo)
63
- file = wiki.file_class.new(wiki).populate(blob, self.dir)
62
+ blob = self.blob(wiki.repo)
63
+ file = wiki.file_class.new(wiki).populate(blob, self.dir)
64
64
  file.version = commit
65
65
  file
66
66
  end
@@ -87,6 +87,7 @@ module Gollum
87
87
  return '' if dir =~ /^.:\/$/
88
88
  if dir
89
89
  dir = ::File.expand_path(dir, '/')
90
+ dir = dir[2..-1] if dir =~ /^[a-zA-Z]:\// # expand_path may add d:/ on windows
90
91
  dir = '' if dir == '/'
91
92
  end
92
93
  dir
@@ -18,7 +18,7 @@ module Gollum
18
18
  # :message - The String commit message.
19
19
  # :name - The String author full name.
20
20
  # :email - The String email address.
21
- # :parent - Optional Grit::Commit parent to this update.
21
+ # :parent - Optional Gollum::Git::Commit parent to this update.
22
22
  # :tree - Optional String SHA of the tree to create the
23
23
  # index from.
24
24
  # :committer - Optional Gollum::Committer instance. If provided,
@@ -30,17 +30,18 @@ module Gollum
30
30
  @wiki = wiki
31
31
  @options = options
32
32
  @callbacks = []
33
+ after_commit { |*args| Hook.execute(:post_commit, *args) }
33
34
  end
34
35
 
35
36
  # Public: References the Git index for this commit.
36
37
  #
37
- # Returns a Grit::Index.
38
+ # Returns a Gollum::Git::Index.
38
39
  def index
39
40
  @index ||= begin
40
41
  idx = @wiki.repo.index
41
- if tree = options[:tree]
42
+ if (tree = options[:tree])
42
43
  idx.read_tree(tree)
43
- elsif parent = parents.first
44
+ elsif (parent = parents.first)
44
45
  idx.read_tree(parent.tree.id)
45
46
  end
46
47
  idx
@@ -49,18 +50,18 @@ module Gollum
49
50
 
50
51
  # Public: The committer for this commit.
51
52
  #
52
- # Returns a Grit::Actor.
53
+ # Returns a Gollum::Git::Actor.
53
54
  def actor
54
55
  @actor ||= begin
55
- @options[:name] = @wiki.default_committer_name if @options[:name].to_s.empty?
56
- @options[:email] = @wiki.default_committer_email if @options[:email].to_s.empty?
57
- Grit::Actor.new(@options[:name], @options[:email])
56
+ @options[:name] = @wiki.default_committer_name if @options[:name].nil?
57
+ @options[:email] = @wiki.default_committer_email if @options[:email].nil?
58
+ Gollum::Git::Actor.new(@options[:name], @options[:email])
58
59
  end
59
60
  end
60
61
 
61
62
  # Public: The parent commits to this pending commit.
62
63
  #
63
- # Returns an array of Grit::Commit instances.
64
+ # Returns an array of Gollum::Git::Commit instances.
64
65
  def parents
65
66
  @parents ||= begin
66
67
  arr = [@options[:parent] || @wiki.repo.commit(@wiki.ref)]
@@ -91,12 +92,12 @@ module Gollum
91
92
 
92
93
  path = @wiki.page_file_name(name, format)
93
94
 
94
- dir = '/' if dir.strip.empty?
95
+ dir = '/' if dir.strip.empty?
95
96
 
96
- fullpath = ::File.join(*[@wiki.page_file_dir, dir, path].compact)
97
+ fullpath = ::File.join(*[dir, path])
97
98
  fullpath = fullpath[1..-1] if fullpath =~ /^\//
98
99
 
99
- if index.current_tree && tree = index.current_tree / (@wiki.page_file_dir || '/')
100
+ if index.current_tree && (tree = index.current_tree / (@wiki.page_file_dir || '/'))
100
101
  tree = tree / dir unless tree.nil?
101
102
  end
102
103
 
@@ -105,8 +106,8 @@ module Gollum
105
106
 
106
107
  tree.blobs.each do |blob|
107
108
  next if page_path_scheduled_for_deletion?(index.tree, fullpath)
108
-
109
- existing_file = blob.name.downcase.sub(/\.\w+$/, '')
109
+
110
+ existing_file = blob.name.downcase.sub(/\.\w+$/, '')
110
111
  existing_file_ext = ::File.extname(blob.name).sub(/^\./, '')
111
112
 
112
113
  new_file_ext = ::File.extname(path).sub(/^\./, '')
@@ -119,7 +120,13 @@ module Gollum
119
120
 
120
121
  fullpath = fullpath.force_encoding('ascii-8bit') if fullpath.respond_to?(:force_encoding)
121
122
 
122
- index.add(fullpath, @wiki.normalize(data))
123
+ begin
124
+ data = @wiki.normalize(data)
125
+ rescue ArgumentError => err
126
+ # Swallow errors that arise from data being binary
127
+ raise err unless err.message.include?('invalid byte sequence')
128
+ end
129
+ index.add(fullpath, data)
123
130
  end
124
131
 
125
132
  # Update the given file in the repository's working directory if there
@@ -133,24 +140,24 @@ module Gollum
133
140
  # Returns nothing.
134
141
  def update_working_dir(dir, name, format)
135
142
  unless @wiki.repo.bare
136
- if @wiki.page_file_dir
137
- dir = dir.size.zero? ? @wiki.page_file_dir : ::File.join(dir, @wiki.page_file_dir)
143
+ if @wiki.page_file_dir && dir !~ /^#{@wiki.page_file_dir}/
144
+ dir = dir.size.zero? ? @wiki.page_file_dir : ::File.join(@wiki.page_file_dir, dir)
138
145
  end
139
146
 
140
147
  path =
141
- if dir == ''
142
- @wiki.page_file_name(name, format)
143
- else
144
- ::File.join(dir, @wiki.page_file_name(name, format))
145
- end
148
+ if dir == ''
149
+ @wiki.page_file_name(name, format)
150
+ else
151
+ ::File.join(dir, @wiki.page_file_name(name, format))
152
+ end
146
153
 
147
154
  path = path.force_encoding('ascii-8bit') if path.respond_to?(:force_encoding)
148
155
 
149
156
  Dir.chdir(::File.join(@wiki.repo.path, '..')) do
150
157
  if file_path_scheduled_for_deletion?(index.tree, path)
151
- @wiki.repo.git.rm({'f' => true}, '--', path)
158
+ @wiki.repo.git.rm(path, :force => true)
152
159
  else
153
- @wiki.repo.git.checkout({}, 'HEAD', '--', path)
160
+ @wiki.repo.git.checkout(path, 'HEAD')
154
161
  end
155
162
  end
156
163
  end
@@ -159,8 +166,9 @@ module Gollum
159
166
  # Writes the commit to Git and runs the after_commit callbacks.
160
167
  #
161
168
  # Returns the String SHA1 of the new commit.
162
- def commit
163
- sha1 = index.commit(@options[:message], parents, actor, nil, @wiki.ref)
169
+ def commit(update_ref = true)
170
+ head = update_ref ? @wiki.ref : nil
171
+ sha1 = index.commit(@options[:message], parents, actor, nil, head)
164
172
  @callbacks.each do |cb|
165
173
  cb.call(self, sha1)
166
174
  end
@@ -191,11 +199,11 @@ module Gollum
191
199
  parts = path.split('/')
192
200
  if parts.size == 1
193
201
  deletions = map.keys.select { |k| !map[k] }
194
- downfile = parts.first.downcase.sub(/\.\w+$/, '')
202
+ downfile = parts.first.downcase.sub(/\.\w+$/, '')
195
203
  deletions.any? { |d| d.downcase.sub(/\.\w+$/, '') == downfile }
196
204
  else
197
205
  part = parts.shift
198
- if rest = map[part]
206
+ if (rest = map[part])
199
207
  page_path_scheduled_for_deletion?(rest, parts.join('/'))
200
208
  else
201
209
  false
@@ -219,7 +227,7 @@ module Gollum
219
227
  deletions.any? { |d| d == parts.first }
220
228
  else
221
229
  part = parts.shift
222
- if rest = map[part]
230
+ if (rest = map[part])
223
231
  file_path_scheduled_for_deletion?(rest, parts.join('/'))
224
232
  else
225
233
  false
@@ -229,7 +237,6 @@ module Gollum
229
237
 
230
238
  # Proxies methods t
231
239
  def method_missing(name, *args)
232
- args.map! { |item| item.respond_to?(:force_encoding) ? item.force_encoding('ascii-8bit') : item }
233
240
  index.send(name, *args)
234
241
  end
235
242
  end