dolt 0.1.1 → 0.2.0

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 (62) hide show
  1. data/Gemfile.lock +25 -5
  2. data/Readme.md +90 -16
  3. data/bin/dolt +22 -4
  4. data/dolt.gemspec +10 -2
  5. data/lib/dolt/disk_repo_resolver.rb +3 -5
  6. data/lib/dolt/git/blame.rb +112 -0
  7. data/lib/dolt/git/commit.rb +73 -0
  8. data/lib/dolt/git/repository.rb +26 -24
  9. data/lib/dolt/repo_actions.rb +32 -19
  10. data/lib/dolt/sinatra/actions.rb +51 -18
  11. data/lib/dolt/sinatra/multi_repo_browser.rb +30 -3
  12. data/lib/dolt/sinatra/single_repo_browser.rb +36 -2
  13. data/lib/dolt/template_renderer.rb +7 -8
  14. data/lib/dolt/version.rb +1 -1
  15. data/lib/dolt/view.rb +3 -61
  16. data/lib/dolt/view/blame.rb +57 -0
  17. data/lib/dolt/view/blob.rb +60 -0
  18. data/lib/dolt/view/breadcrumb.rb +10 -17
  19. data/lib/dolt/{git/blob.rb → view/commit.rb} +5 -11
  20. data/lib/dolt/view/gravatar.rb +29 -0
  21. data/lib/dolt/{git/shell.rb → view/markup.rb} +10 -16
  22. data/lib/dolt/view/multi_repository.rb +27 -0
  23. data/lib/dolt/{async/deferrable_child_process.rb → view/object.rb} +11 -24
  24. data/lib/dolt/view/single_repository.rb +27 -0
  25. data/lib/dolt/view/smart_blob_renderer.rb +33 -0
  26. data/lib/dolt/view/syntax_highlight.rb +86 -0
  27. data/lib/dolt/view/tree.rb +69 -0
  28. data/test/dolt/git/blame_test.rb +128 -0
  29. data/test/dolt/git/commit_test.rb +89 -0
  30. data/test/dolt/git/repository_test.rb +24 -73
  31. data/test/dolt/repo_actions_test.rb +77 -15
  32. data/test/dolt/sinatra/actions_test.rb +168 -8
  33. data/test/dolt/template_renderer_test.rb +44 -10
  34. data/test/dolt/templates/blame_test.rb +56 -0
  35. data/test/dolt/{views → templates}/blob_test.rb +44 -34
  36. data/test/dolt/templates/commits_test.rb +61 -0
  37. data/test/dolt/templates/raw_test.rb +41 -0
  38. data/test/dolt/templates/tree_test.rb +51 -0
  39. data/test/dolt/view/blame_test.rb +122 -0
  40. data/test/dolt/view/blob_test.rb +90 -0
  41. data/test/dolt/view/breadcrumb_test.rb +46 -0
  42. data/test/dolt/view/commit_test.rb +31 -0
  43. data/test/dolt/view/gravatar_test.rb +30 -0
  44. data/test/dolt/view/markup_test.rb +30 -0
  45. data/test/dolt/{git/blob_test.rb → view/multi_repository_test.rb} +10 -24
  46. data/test/dolt/view/object_test.rb +71 -0
  47. data/test/dolt/view/single_repository_test.rb +30 -0
  48. data/test/dolt/{view_test.rb → view/syntax_highlight_test.rb} +40 -27
  49. data/test/dolt/view/tree_test.rb +115 -0
  50. data/test/test_helper.rb +18 -13
  51. data/vendor/ui/css/gitorious.css +20 -8
  52. data/views/blame.erb +41 -0
  53. data/views/blob.erb +6 -9
  54. data/views/commits.erb +23 -0
  55. data/views/index.erb +25 -0
  56. data/views/raw.erb +19 -0
  57. data/views/tree.erb +28 -26
  58. metadata +156 -26
  59. data/lib/dolt/git/tree.rb +0 -65
  60. data/lib/dolt/view/highlighter.rb +0 -52
  61. data/test/dolt/git/shell_test.rb +0 -112
  62. data/test/dolt/git/tree_test.rb +0 -120
data/lib/dolt/git/tree.rb DELETED
@@ -1,65 +0,0 @@
1
- # encoding: utf-8
2
- #--
3
- # Copyright (C) 2012 Gitorious AS
4
- #
5
- # This program is free software: you can redistribute it and/or modify
6
- # it under the terms of the GNU Affero General Public License as published by
7
- # the Free Software Foundation, either version 3 of the License, or
8
- # (at your option) any later version.
9
- #
10
- # This program is distributed in the hope that it will be useful,
11
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- # GNU Affero General Public License for more details.
14
- #
15
- # You should have received a copy of the GNU Affero General Public License
16
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
- #++
18
- module Dolt
19
- module Git
20
- class Tree
21
- attr_reader :path, :entries
22
-
23
- def initialize(path, entries)
24
- @path = path
25
- @entries = entries
26
- end
27
-
28
- def self.parse(path, ls_tree_payload)
29
- path = path == "" ? "./" : path
30
-
31
- entries = ls_tree_payload.split("\n").collect do |line|
32
- pieces = line.split(/\s+/)
33
- klass = pieces[1] == "blob" ? File : Dir
34
- klass.new(pieces[3], pieces[2], pieces[0])
35
- end
36
-
37
- dirs = entries.reject { |e| e.file? }.sort_by(&:path)
38
- files = entries.reject { |e| e.dir? }.sort_by(&:path)
39
- new(path, dirs + files)
40
- end
41
-
42
- class Entry
43
- attr_reader :full_path, :path, :sha, :mode
44
-
45
- def initialize(path, sha, mode)
46
- @full_path = path
47
- @path = ::File.basename(path)
48
- @sha = sha
49
- @mode = mode
50
- end
51
-
52
- def file?; false; end
53
- def dir?; false; end
54
- end
55
-
56
- class File < Entry
57
- def file?; true; end
58
- end
59
-
60
- class Dir < Entry
61
- def dir?; true; end
62
- end
63
- end
64
- end
65
- end
@@ -1,52 +0,0 @@
1
- # encoding: utf-8
2
- #--
3
- # Copyright (C) 2012 Gitorious AS
4
- #
5
- # This program is free software: you can redistribute it and/or modify
6
- # it under the terms of the GNU Affero General Public License as published by
7
- # the Free Software Foundation, either version 3 of the License, or
8
- # (at your option) any later version.
9
- #
10
- # This program is distributed in the hope that it will be useful,
11
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- # GNU Affero General Public License for more details.
14
- #
15
- # You should have received a copy of the GNU Affero General Public License
16
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
- #++
18
- require "pygments"
19
-
20
- module Dolt
21
- module View
22
- class Highlighter
23
- def initialize(options = {})
24
- @options = options
25
- options[:options] ||= {}
26
- options[:options][:nowrap] = true
27
- options[:options][:encoding] = options[:options][:encoding]|| "utf-8"
28
- end
29
-
30
- def highlight(code, lexer)
31
- Pygments.highlight(code, options.merge(:lexer => lexer))
32
- end
33
-
34
- def self.lexer(suffix)
35
- @@lexer_aliases[suffix] || suffix
36
- end
37
-
38
- def self.add_lexer_alias(extension, lexer)
39
- @@lexer_aliases ||= {}
40
- @@lexer_aliases[extension] = lexer
41
- end
42
-
43
- private
44
- def options; @options; end
45
- end
46
- end
47
- end
48
-
49
- Dolt::View::Highlighter.add_lexer_alias("yml", "yaml")
50
- Dolt::View::Highlighter.add_lexer_alias("Rakefile", "rb")
51
- Dolt::View::Highlighter.add_lexer_alias("Gemfile", "rb")
52
- Dolt::View::Highlighter.add_lexer_alias("gemspec", "rb")
@@ -1,112 +0,0 @@
1
- # encoding: utf-8
2
- #--
3
- # Copyright (C) 2012 Gitorious AS
4
- #
5
- # This program is free software: you can redistribute it and/or modify
6
- # it under the terms of the GNU Affero General Public License as published by
7
- # the Free Software Foundation, either version 3 of the License, or
8
- # (at your option) any later version.
9
- #
10
- # This program is distributed in the hope that it will be useful,
11
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- # GNU Affero General Public License for more details.
14
- #
15
- # You should have received a copy of the GNU Affero General Public License
16
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
- #++
18
- require "test_helper"
19
- require "mocha"
20
- require "eventmachine"
21
- require "dolt/git/shell"
22
-
23
- describe Dolt::Git::Shell do
24
- include EM::MiniTest::Spec
25
- include Dolt::StdioStub
26
-
27
- describe "#git" do
28
- it "assumes git dir in work tree" do
29
- expected_cmd = ["git --git-dir /somewhere/.git ",
30
- "--work-tree /somewhere log"].join
31
- Dolt::DeferrableChildProcess.expects(:open).with(expected_cmd)
32
- git = Dolt::Git::Shell.new("/somewhere")
33
- git.git("log")
34
- end
35
-
36
- it "uses provided git dir" do
37
- expected_cmd = ["git --git-dir /somewhere/.git ",
38
- "--work-tree /elsewhere log"].join
39
- Dolt::DeferrableChildProcess.expects(:open).with(expected_cmd)
40
- git = Dolt::Git::Shell.new("/elsewhere", "/somewhere/.git")
41
- git.git("log")
42
- end
43
-
44
- it "returns deferrable" do
45
- silence_stderr do
46
- git = Dolt::Git::Shell.new("/somwhere")
47
- result = git.git("log")
48
-
49
- assert result.respond_to?(:callback)
50
- assert result.respond_to?(:errback)
51
- end
52
- end
53
-
54
- it "joins arguments with spaces" do
55
- expected_cmd = ["git --git-dir /somewhere/.git ",
56
- "--work-tree /somewhere push origin master"].join
57
- Dolt::DeferrableChildProcess.expects(:open).with(expected_cmd)
58
- git = Dolt::Git::Shell.new("/somewhere")
59
- git.git("push", "origin", "master")
60
- end
61
-
62
- it "calls errback when git operation fails" do
63
- silence_stderr do
64
- git = Dolt::Git::Shell.new("/somewhere")
65
- result = git.git("push", "origin", "master")
66
- result.errback do |status|
67
- refute status.nil?
68
- done!
69
- end
70
- wait!
71
- end
72
- end
73
- end
74
-
75
- describe "#show" do
76
- it "shows a file" do
77
- git = Dolt::Git::Shell.new("/somewhere")
78
- git.expects(:git).with("show", "master:app/models/repository.rb")
79
- result = git.show("app/models/repository.rb", "master")
80
- end
81
- end
82
-
83
- describe "#ls_tree" do
84
- it "lists tree root" do
85
- git = Dolt::Git::Shell.new("/somewhere")
86
- git.expects(:git).with("ls-tree", "master", "./")
87
-
88
- result = git.ls_tree("", "master")
89
- end
90
-
91
- it "lists tree root when starting with slash" do
92
- git = Dolt::Git::Shell.new("/somewhere")
93
- git.expects(:git).with("ls-tree", "master", "./")
94
-
95
- result = git.ls_tree("/", "master")
96
- end
97
-
98
- it "lists path with trailing slash" do
99
- git = Dolt::Git::Shell.new("/somewhere")
100
- git.expects(:git).with("ls-tree", "master", "./app/models/")
101
-
102
- result = git.ls_tree("app/models", "master")
103
- end
104
-
105
- it "lists path at given ref" do
106
- git = Dolt::Git::Shell.new("/somewhere")
107
- git.expects(:git).with("ls-tree", "v2.0.0", "./app/models/")
108
-
109
- result = git.ls_tree("app/models/", "v2.0.0")
110
- end
111
- end
112
- end
@@ -1,120 +0,0 @@
1
- # encoding: utf-8
2
- #--
3
- # Copyright (C) 2012 Gitorious AS
4
- #
5
- # This program is free software: you can redistribute it and/or modify
6
- # it under the terms of the GNU Affero General Public License as published by
7
- # the Free Software Foundation, either version 3 of the License, or
8
- # (at your option) any later version.
9
- #
10
- # This program is distributed in the hope that it will be useful,
11
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- # GNU Affero General Public License for more details.
14
- #
15
- # You should have received a copy of the GNU Affero General Public License
16
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
- #++
18
- require "test_helper"
19
- require "dolt/git/tree"
20
-
21
- describe Dolt::Git::Tree do
22
- describe "parsing root tree" do
23
- before do
24
- lines = <<-GIT
25
- 100644 blob e90021f89616ddf86855d05337c188408d3b417e .gitmodules
26
- 100644 blob c80ee3697054566d1a4247d80be78ec3ddfde295 Gemfile
27
- 100644 blob 0053b3c95b0d9faa4916f7cd5e559c2b0f138027 Gemfile.lock
28
- 100644 blob 2ad22ff4b188c256d8ac97ded87c1c6ef6e96e43 Rakefile
29
- 100644 blob c8d1d197abfcd0f96c47583ec5f4328565cba433 Readme.md
30
- 040000 tree 18052467e73a1b7fb2613dc7b36baa554fab024b bin
31
- 100644 blob e83bb675977e7277698320cdd9c595c5698e5aa5 dolt.gemspec
32
- 040000 tree 4b051dd46c3ba70fbfd6a2484ec00121a70bee3a lib
33
- 040000 tree 86b096dc99b2cba28daa7676ed0dd38f709527b2 test
34
- 040000 tree d74d6bcb50cc5de9eb8fe019d7798b04d3a427e9 vendor
35
- 040000 tree be8fb09b735ac23265db2bec7c23e022a99ee730 views
36
- GIT
37
-
38
- @tree = Dolt::Git::Tree.parse("", lines)
39
- end
40
-
41
- it "has path" do
42
- assert_equal "./", @tree.path
43
- end
44
-
45
- it "extracts each line as an entry" do
46
- assert_equal 11, @tree.entries.length
47
- end
48
-
49
- it "extracts file entry objects" do
50
- gemfile = @tree.entries[6]
51
-
52
- assert gemfile.file?
53
- assert !gemfile.dir?
54
- assert_equal "Gemfile", gemfile.path
55
- assert_equal "Gemfile", gemfile.full_path
56
- assert_equal "100644", gemfile.mode
57
- assert_equal "c80ee3697054566d1a4247d80be78ec3ddfde295", gemfile.sha
58
- end
59
-
60
- it "extracts directory entry objects" do
61
- bin = @tree.entries[0]
62
-
63
- assert !bin.file?
64
- assert bin.dir?
65
- assert_equal "bin", bin.path
66
- assert_equal "040000", bin.mode
67
- assert_equal "18052467e73a1b7fb2613dc7b36baa554fab024b", bin.sha
68
- end
69
- end
70
-
71
- describe "parsing nested tree" do
72
- before do
73
- lines = <<-GIT
74
- 040000 tree c1d92125977841b672a10c96c6800e1b360a4e62 lib/dolt/async
75
- 100644 blob 6da3991090ba2df53eabe05bf4330aadf370a43a lib/dolt/disk_repo_resolver.rb
76
- 040000 tree 0142bdb42936094cdd92aa188d3193be85f7a6c1 lib/dolt/git
77
- 100644 blob 2b8674702e62aaa5607317ed83085e74a62b9781 lib/dolt/repo_actions.rb
78
- 040000 tree d93b4afc62ad460387cf5d91d98d1ad306219419 lib/dolt/sinatra
79
- 100644 blob 2a7e89f4b940e23a3d921199d9000e93da299872 lib/dolt/template_renderer.rb
80
- 100644 blob dfe78a965009e27d9cce7c9733787acb564b6630 lib/dolt/version.rb
81
- 100644 blob 685369dd2a66f0313b232ee898f8bbdafec6862d lib/dolt/view.rb
82
- 040000 tree 78347f337aaa613eb0a1c27ae7f89e39a22dcd6f lib/dolt/view
83
- GIT
84
-
85
- @tree = Dolt::Git::Tree.parse("lib/dolt", lines)
86
- end
87
-
88
- it "does not include ./ in path" do
89
- assert_equal "lib/dolt", @tree.path
90
- end
91
-
92
- it "strips root path from entries" do
93
- assert_equal "disk_repo_resolver.rb", @tree.entries[4].path
94
- end
95
-
96
- it "groups tree by type, dirs first" do
97
- assert @tree.entries[0].dir?
98
- assert @tree.entries[1].dir?
99
- assert @tree.entries[2].dir?
100
- assert @tree.entries[3].dir?
101
- assert @tree.entries[4].file?
102
- assert @tree.entries[5].file?
103
- assert @tree.entries[6].file?
104
- assert @tree.entries[7].file?
105
- assert @tree.entries[8].file?
106
- end
107
-
108
- it "sorts tree entries alphabetically" do
109
- assert_equal "async", @tree.entries[0].path
110
- assert_equal "git", @tree.entries[1].path
111
- assert_equal "sinatra", @tree.entries[2].path
112
- assert_equal "view", @tree.entries[3].path
113
- assert_equal "disk_repo_resolver.rb", @tree.entries[4].path
114
- assert_equal "repo_actions.rb", @tree.entries[5].path
115
- assert_equal "template_renderer.rb", @tree.entries[6].path
116
- assert_equal "version.rb", @tree.entries[7].path
117
- assert_equal "view.rb", @tree.entries[8].path
118
- end
119
- end
120
- end