git_presenter 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.
- data/.travis.yml +5 -0
- data/README.markdown +15 -13
- data/VERSION +1 -1
- data/bin/git-presenter +4 -1
- data/git_presenter.gemspec +12 -5
- data/lib/git_presenter/parser.rb +16 -0
- data/lib/git_presenter/presentation.rb +104 -0
- data/lib/git_presenter/slide.rb +30 -0
- data/lib/git_presenter/writer.rb +32 -0
- data/lib/git_presenter.rb +10 -107
- data/spec/integration/initialize_presentation_spec.rb +18 -8
- data/spec/integration/moving_through_presentation_spec.rb +80 -19
- data/spec/integration/start_presentation_spec.rb +20 -8
- data/spec/lib/git_presenter/presentation_spec.rb +87 -0
- data/spec/lib/git_presenter/slide_spec.rb +38 -0
- data/spec/lib/git_presenter/writer_spec.rb +4 -0
- data/spec/spec_helper.rb +3 -2
- data/spec/support/command_line_helper.rb +18 -0
- data/spec/support/git_helpers.rb +95 -0
- metadata +23 -16
- data/spec/integration/processing_user_command_spec.rb +0 -61
- data/spec/integration/status_line_spec.rb +0 -8
- data/spec/support/repo_helpers.rb +0 -65
data/.travis.yml
ADDED
data/README.markdown
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
# git-presenter
|
2
2
|
|
3
|
+
[](http://travis-ci.org/pythonandchips/git-presenter)
|
4
|
+
|
3
5
|
When presenting code live on stage you have a few choices:
|
6
|
+
|
4
7
|
* Change code live on stage and risk making a mistake and the code not working.
|
5
8
|
* Place code in a slide and not be able to run the code live.
|
6
9
|
|
@@ -14,25 +17,24 @@ Any and all feedback is welcome
|
|
14
17
|
## Pre-requisites
|
15
18
|
|
16
19
|
* Git
|
17
|
-
* Ruby
|
20
|
+
* Ruby version 1.9.2 or 1.9.3 or jruby in 1.9 mode (basically anything with 1.9 at the end)
|
18
21
|
|
19
22
|
## Installation
|
20
23
|
|
21
|
-
gem install
|
24
|
+
gem install git_presenter
|
22
25
|
|
23
26
|
## Usage
|
24
27
|
|
25
|
-
Commit to git as you develop
|
26
|
-
When the code is ready use the "git-presenter init" command to initialise
|
27
|
-
Once it is initialised you can start the presentation with "git-presenter start"
|
28
|
-
Then use the following command to navigate the presentation
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
help/h: display this message
|
28
|
+
* Commit to git as you develop your code.
|
29
|
+
* When the code is ready use the "git-presenter init" command to initialise
|
30
|
+
* Once it is initialised you can start the presentation with "git-presenter start"
|
31
|
+
* Then use the following command to navigate the presentation
|
32
|
+
* next/n: move to next slide
|
33
|
+
* back/b: move back a slide
|
34
|
+
* end/e: move to end of presentation
|
35
|
+
* start/s: move to start of presentation
|
36
|
+
* list/l : list slides in presentation
|
37
|
+
* help/h: display this message
|
36
38
|
|
37
39
|
## Contributing to git-presenter
|
38
40
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/bin/git-presenter
CHANGED
@@ -10,9 +10,12 @@ if ARGV[0] == "init"
|
|
10
10
|
puts "run 'git-presenter start' to begin the presentation"
|
11
11
|
elsif ARGV[0] == "start"
|
12
12
|
presenter = GitPresenter.start_presentation(Dir.pwd)
|
13
|
+
puts presenter.current_slide
|
13
14
|
|
14
15
|
while command = Readline.readline(presenter.status_line, true)
|
15
|
-
|
16
|
+
result = presenter.execute(command)
|
17
|
+
exit if result == :exit
|
18
|
+
puts result
|
16
19
|
end
|
17
20
|
else
|
18
21
|
puts "what you talkin bout willis"
|
data/git_presenter.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "git_presenter"
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Colin Gemmell"]
|
12
|
-
s.date = "2012-03-
|
12
|
+
s.date = "2012-03-26"
|
13
13
|
s.description = "Code presentation tool using git"
|
14
14
|
s.email = "pythonandchips@gmail.com"
|
15
15
|
s.executables = ["git-presenter"]
|
@@ -19,6 +19,7 @@ Gem::Specification.new do |s|
|
|
19
19
|
]
|
20
20
|
s.files = [
|
21
21
|
".rspec",
|
22
|
+
".travis.yml",
|
22
23
|
"Gemfile",
|
23
24
|
"Gemfile.lock",
|
24
25
|
"LICENSE.txt",
|
@@ -28,13 +29,19 @@ Gem::Specification.new do |s|
|
|
28
29
|
"bin/git-presenter",
|
29
30
|
"git_presenter.gemspec",
|
30
31
|
"lib/git_presenter.rb",
|
32
|
+
"lib/git_presenter/parser.rb",
|
33
|
+
"lib/git_presenter/presentation.rb",
|
34
|
+
"lib/git_presenter/slide.rb",
|
35
|
+
"lib/git_presenter/writer.rb",
|
31
36
|
"spec/integration/initialize_presentation_spec.rb",
|
32
37
|
"spec/integration/moving_through_presentation_spec.rb",
|
33
|
-
"spec/integration/processing_user_command_spec.rb",
|
34
38
|
"spec/integration/start_presentation_spec.rb",
|
35
|
-
"spec/
|
39
|
+
"spec/lib/git_presenter/presentation_spec.rb",
|
40
|
+
"spec/lib/git_presenter/slide_spec.rb",
|
41
|
+
"spec/lib/git_presenter/writer_spec.rb",
|
36
42
|
"spec/spec_helper.rb",
|
37
|
-
"spec/support/
|
43
|
+
"spec/support/command_line_helper.rb",
|
44
|
+
"spec/support/git_helpers.rb"
|
38
45
|
]
|
39
46
|
s.homepage = "http://github.com/pythonandchips/git-presenter"
|
40
47
|
s.licenses = ["MIT"]
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module GitPresenter
|
2
|
+
class Parser
|
3
|
+
def initialize(presentation_dir)
|
4
|
+
@presentation_dir = presentation_dir
|
5
|
+
end
|
6
|
+
|
7
|
+
def presentation
|
8
|
+
presenter = nil
|
9
|
+
yaml = YAML.parse(File.open(@presentation_dir + "/.presentation", "r")).to_ruby
|
10
|
+
presenter = GitPresenter::Presentation.new(yaml)
|
11
|
+
presenter.start
|
12
|
+
presenter
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
module GitPresenter
|
2
|
+
class Presentation
|
3
|
+
attr_reader :slides, :current_slide
|
4
|
+
|
5
|
+
def initialize(presentation)
|
6
|
+
@slides = presentation["slides"].map{|slide| Slide.new(slide["slide"])}
|
7
|
+
@current_slide = slides.first
|
8
|
+
end
|
9
|
+
|
10
|
+
def command_for(command)
|
11
|
+
return :commit if command =~ /^[0-9]+$/
|
12
|
+
return :command if command[0] == "!"
|
13
|
+
{"n" => :next, "next" => :next,
|
14
|
+
"back" => :previous, "b" => :previous,
|
15
|
+
"start" => :start, "s" => :start,
|
16
|
+
"end" => :end, "e" => :end,
|
17
|
+
"list" => :list, "l" => :list,
|
18
|
+
"help" => :help, "h" => :help,
|
19
|
+
"exit" => :exit
|
20
|
+
}[command]
|
21
|
+
end
|
22
|
+
|
23
|
+
def execute(user_command)
|
24
|
+
command = command_for(user_command)
|
25
|
+
if command.nil?
|
26
|
+
puts "I canny understand ye, gonna try again"
|
27
|
+
return
|
28
|
+
end
|
29
|
+
return commit(user_command.to_i) if command == :commit
|
30
|
+
return bash_command(user_command) if command == :command
|
31
|
+
return :exit if command == :exit
|
32
|
+
self.send(command)
|
33
|
+
end
|
34
|
+
|
35
|
+
def bash_command(user_command)
|
36
|
+
puts `#{user_command[1..-1]}`
|
37
|
+
end
|
38
|
+
|
39
|
+
def status_line
|
40
|
+
"#{position+1}/#{total_slides} >"
|
41
|
+
end
|
42
|
+
|
43
|
+
def position
|
44
|
+
slides.index(@current_slide)
|
45
|
+
end
|
46
|
+
|
47
|
+
def total_slides
|
48
|
+
@slides.length
|
49
|
+
end
|
50
|
+
|
51
|
+
def start
|
52
|
+
@current_slide = slides.first
|
53
|
+
@current_slide.execute
|
54
|
+
end
|
55
|
+
|
56
|
+
def help
|
57
|
+
<<-EOH
|
58
|
+
Git Presenter Reference
|
59
|
+
|
60
|
+
next/n: move to next slide
|
61
|
+
back/b: move back a slide
|
62
|
+
end/e: move to end of presentation
|
63
|
+
start/s: move to start of presentation
|
64
|
+
list/l : list slides in presentation
|
65
|
+
help/h: display this message
|
66
|
+
!(exclimation mark): execute following in terminal
|
67
|
+
exit: exit from the presentation
|
68
|
+
EOH
|
69
|
+
end
|
70
|
+
|
71
|
+
def end
|
72
|
+
@current_slide = slides.last
|
73
|
+
@current_slide.execute
|
74
|
+
end
|
75
|
+
|
76
|
+
def commit(slide_number)
|
77
|
+
@current_slide = slides[slide_number - 1]
|
78
|
+
@current_slide.execute
|
79
|
+
end
|
80
|
+
|
81
|
+
def next
|
82
|
+
return if position.nil?
|
83
|
+
@current_slide = slides[position + 1] || @current_slide
|
84
|
+
@current_slide.execute
|
85
|
+
end
|
86
|
+
|
87
|
+
def previous
|
88
|
+
return @current_slide if position == 0
|
89
|
+
@current_slide = slides[position - 1]
|
90
|
+
@current_slide.execute
|
91
|
+
end
|
92
|
+
|
93
|
+
def list
|
94
|
+
@slides.map do |slide|
|
95
|
+
if slide == @current_slide
|
96
|
+
"*#{slide}"
|
97
|
+
else
|
98
|
+
slide
|
99
|
+
end
|
100
|
+
end.join("\n")
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module GitPresenter
|
2
|
+
class Slide
|
3
|
+
attr_reader :commit, :message, :run
|
4
|
+
|
5
|
+
def initialize(slide)
|
6
|
+
@commit = slide["commit"]
|
7
|
+
@message = slide["message"]
|
8
|
+
@run = slide["run"]
|
9
|
+
end
|
10
|
+
|
11
|
+
def execute
|
12
|
+
output = ""
|
13
|
+
output << checkout unless @commit.nil?
|
14
|
+
output << `#{run}` unless @run.nil?
|
15
|
+
output
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_s
|
19
|
+
"#{@commit[0..9]}, #{@message}"
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def checkout
|
25
|
+
`git checkout -q . `
|
26
|
+
`git checkout -q #{@commit}`
|
27
|
+
@message + "\n"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module GitPresenter
|
2
|
+
class Writer
|
3
|
+
CONFIG_FILE = ".presentation"
|
4
|
+
|
5
|
+
def initialize(file_path)
|
6
|
+
@presentation_dir = file_path
|
7
|
+
end
|
8
|
+
|
9
|
+
def output_presenatation_file
|
10
|
+
yaml = {"slides" => create_slides}.to_yaml
|
11
|
+
File.open(presentation_file_location, "w") do |file|
|
12
|
+
file.write(yaml)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def presentation_file_location
|
19
|
+
File.join(@presentation_dir, CONFIG_FILE)
|
20
|
+
end
|
21
|
+
|
22
|
+
def create_slides
|
23
|
+
repo = Grit::Repo.new(".", "master")
|
24
|
+
repo.commits.reverse.map do |commit|
|
25
|
+
{"slide" =>
|
26
|
+
{"commit" => commit.id,
|
27
|
+
"message" => commit.message}
|
28
|
+
}
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/git_presenter.rb
CHANGED
@@ -1,116 +1,19 @@
|
|
1
1
|
require "grit"
|
2
|
+
require "yaml"
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
module GitPresenter
|
5
|
+
require "git_presenter/presentation"
|
6
|
+
require "git_presenter/writer"
|
7
|
+
require "git_presenter/parser"
|
8
|
+
require "git_presenter/slide"
|
8
9
|
|
9
10
|
def self.initialise_presentation dir
|
10
|
-
|
11
|
-
|
12
|
-
repo.commits.reverse.each do |commit|
|
13
|
-
file.write("#{commit.id}\n")
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def commits
|
19
|
-
@commits
|
11
|
+
builder = Writer.new(dir)
|
12
|
+
builder.output_presenatation_file
|
20
13
|
end
|
21
14
|
|
22
15
|
def self.start_presentation dir
|
23
|
-
|
24
|
-
|
25
|
-
commits = file.lines.map{|line| line.strip}
|
26
|
-
presenter = GitPresenter.new(commits)
|
27
|
-
presenter.start
|
28
|
-
end
|
29
|
-
presenter
|
30
|
-
end
|
31
|
-
|
32
|
-
def command_for(command)
|
33
|
-
return :commit if command =~ /^[0-9]+$/
|
34
|
-
{"n" => :next, "next" => :next,
|
35
|
-
"back" => :previous, "b" => :previous,
|
36
|
-
"start" => :start, "s" => :start,
|
37
|
-
"end" => :end, "e" => :end,
|
38
|
-
"list" => :list, "l" => :list,
|
39
|
-
"help" => :help, "h" => :help
|
40
|
-
}[command]
|
41
|
-
end
|
42
|
-
|
43
|
-
def execute(user_command)
|
44
|
-
command = command_for(user_command)
|
45
|
-
if command.nil?
|
46
|
-
puts "I canny understand ye, gonna try again"
|
47
|
-
return
|
48
|
-
end
|
49
|
-
return commit(user_command.to_i) if command == :commit
|
50
|
-
self.send(command)
|
51
|
-
end
|
52
|
-
|
53
|
-
def status_line
|
54
|
-
"#{position+1}/#{total_slides} >"
|
55
|
-
end
|
56
|
-
|
57
|
-
def position
|
58
|
-
commits.index(@current_commit)
|
59
|
-
end
|
60
|
-
|
61
|
-
def total_slides
|
62
|
-
@commits.length
|
63
|
-
end
|
64
|
-
|
65
|
-
|
66
|
-
def start
|
67
|
-
@current_commit = commits.first
|
68
|
-
checkout_current
|
69
|
-
end
|
70
|
-
|
71
|
-
def help
|
72
|
-
<<-EOH
|
73
|
-
Git Presenter Reference
|
74
|
-
|
75
|
-
next/n: move to next slide
|
76
|
-
back/b: move back a slide
|
77
|
-
end/e: move to end of presentation
|
78
|
-
start/s: move to start of presentation
|
79
|
-
list/l : list slides in presentation
|
80
|
-
help/h: display this message
|
81
|
-
EOH
|
82
|
-
end
|
83
|
-
|
84
|
-
def end
|
85
|
-
@current_commit = commits.last
|
86
|
-
checkout_current
|
87
|
-
end
|
88
|
-
|
89
|
-
def commit(slide_number)
|
90
|
-
@current_commit = commits[slide_number - 1]
|
91
|
-
checkout_current
|
92
|
-
end
|
93
|
-
|
94
|
-
def next
|
95
|
-
return if position.nil?
|
96
|
-
@current_commit = commits[position + 1]
|
97
|
-
checkout_current
|
98
|
-
end
|
99
|
-
|
100
|
-
def previous
|
101
|
-
position = commits.index(@current_commit)
|
102
|
-
@current_commit = commits[position - 1]
|
103
|
-
checkout_current
|
104
|
-
end
|
105
|
-
|
106
|
-
def list
|
107
|
-
commits = @commits.dup
|
108
|
-
position = commits.index(@current_commit)
|
109
|
-
commits[position] = "*#{commits[position]}"
|
110
|
-
commits.join("\n")
|
111
|
-
end
|
112
|
-
|
113
|
-
def checkout_current
|
114
|
-
`git checkout #{@current_commit}`
|
16
|
+
parser = Parser.new(dir)
|
17
|
+
parser.presentation
|
115
18
|
end
|
116
19
|
end
|
@@ -1,30 +1,40 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe "initializing a presentation" do
|
4
|
-
let(:presentation_dir){
|
4
|
+
let(:presentation_dir){GitHelper.presentation_dir}
|
5
|
+
|
6
|
+
before do
|
7
|
+
@helper = GitHelper.new(presentation_dir)
|
8
|
+
end
|
5
9
|
|
6
10
|
context ".presentation file" do
|
7
11
|
it "should be written to root directory" do
|
8
|
-
initialise_presentation do
|
12
|
+
@helper.initialise_presentation do
|
9
13
|
File.exists?(".presentation").should be_true
|
10
14
|
end
|
11
15
|
end
|
12
16
|
|
17
|
+
it "should have a slides node" do
|
18
|
+
@helper.initialise_presentation do |commits, yaml|
|
19
|
+
yaml["slides"].should_not be_nil
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
13
23
|
it "should contain a line for each commit to the repository" do
|
14
|
-
initialise_presentation do |commits,
|
15
|
-
|
24
|
+
@helper.initialise_presentation do |commits, yaml|
|
25
|
+
yaml["slides"].length.should eql commits.length
|
16
26
|
end
|
17
27
|
end
|
18
28
|
|
19
29
|
it "first line should contain the first commit number" do
|
20
|
-
initialise_presentation(true) do |commits,
|
21
|
-
|
30
|
+
@helper.initialise_presentation(true) do |commits, yaml|
|
31
|
+
yaml["slides"][0]["slide"]["commit"].should eql commits.first.id
|
22
32
|
end
|
23
33
|
end
|
24
34
|
|
25
35
|
it "second line should contain the second commit number" do
|
26
|
-
initialise_presentation(true) do |commits,
|
27
|
-
|
36
|
+
@helper.initialise_presentation(true) do |commits, yaml|
|
37
|
+
yaml["slides"][1]["slide"]["commit"].should eql commits[1].id
|
28
38
|
end
|
29
39
|
end
|
30
40
|
end
|
@@ -3,80 +3,108 @@ require "spec_helper"
|
|
3
3
|
describe "while giving presentation" do
|
4
4
|
let(:presentation_dir){File.dirname(__FILE__) + "/../../presentation"}
|
5
5
|
|
6
|
+
before do
|
7
|
+
@helper = GitHelper.new(presentation_dir)
|
8
|
+
end
|
9
|
+
|
6
10
|
context "when moving to the next slide" do
|
7
11
|
it "should move to the next commit" do
|
8
|
-
start_presentation do |commits, presenter|
|
12
|
+
@helper.start_presentation do |commits, presenter|
|
9
13
|
presenter.execute("next")
|
10
|
-
head_position.should eql commits[1].id
|
14
|
+
@helper.head_position.should eql commits[1].id
|
11
15
|
end
|
12
16
|
end
|
13
17
|
|
14
18
|
it "should continue till the last commit" do
|
15
|
-
start_presentation do |commits, presenter|
|
19
|
+
@helper.start_presentation do |commits, presenter|
|
20
|
+
presenter.execute("next")
|
21
|
+
presenter.execute("next")
|
22
|
+
@helper.head_position.should eql commits[2].id
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context "when a change has been made during a slide" do
|
28
|
+
it "should continue till the last commit" do
|
29
|
+
@helper.start_presentation do |commits, presenter|
|
16
30
|
presenter.execute("next")
|
31
|
+
@helper.edit_file("inner commit")
|
17
32
|
presenter.execute("next")
|
18
|
-
head_position.should eql commits[2].id
|
33
|
+
@helper.head_position.should eql commits[2].id
|
19
34
|
end
|
20
35
|
end
|
21
36
|
end
|
22
37
|
|
23
38
|
context "when the presentation reaches the end" do
|
24
39
|
it "should stay on the last commit" do
|
25
|
-
start_presentation do |commits, presenter|
|
40
|
+
@helper.start_presentation do |commits, presenter|
|
26
41
|
presenter.execute("next")
|
27
42
|
presenter.execute("next")
|
28
43
|
presenter.execute("next")
|
29
44
|
presenter.execute("next")
|
30
|
-
head_position.should eql commits[2].id
|
45
|
+
@helper.head_position.should eql commits[2].id
|
31
46
|
end
|
32
47
|
end
|
33
48
|
end
|
34
49
|
|
35
50
|
context "when going back through the presentation" do
|
36
|
-
it "should
|
37
|
-
start_presentation do |commits, presenter|
|
51
|
+
it "should go back to a previous commit" do
|
52
|
+
@helper.start_presentation do |commits, presenter|
|
38
53
|
presenter.execute("next")
|
39
54
|
presenter.execute("next")
|
40
55
|
presenter.execute("back")
|
41
|
-
head_position.should eql commits[1].id
|
56
|
+
@helper.head_position.should eql commits[1].id
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context "when going back through the presentation and it reaches the begining" do
|
62
|
+
it "should stay on the last commit" do
|
63
|
+
@helper.start_presentation do |commits, presenter|
|
64
|
+
presenter.execute("next")
|
65
|
+
presenter.execute("next")
|
66
|
+
presenter.execute("back")
|
67
|
+
presenter.execute("back")
|
68
|
+
presenter.execute("back")
|
69
|
+
presenter.execute("back")
|
70
|
+
@helper.head_position.should eql commits[0].id
|
42
71
|
end
|
43
72
|
end
|
44
73
|
end
|
45
74
|
|
46
75
|
context "when going back to the start of the presention" do
|
47
76
|
it "should move to the first commit" do
|
48
|
-
start_presentation do |commits, presenter|
|
77
|
+
@helper.start_presentation do |commits, presenter|
|
49
78
|
presenter.execute("next")
|
50
79
|
presenter.execute("next")
|
51
80
|
presenter.execute("start")
|
52
|
-
head_position.should eql commits[0].id
|
81
|
+
@helper.head_position.should eql commits[0].id
|
53
82
|
end
|
54
83
|
end
|
55
84
|
end
|
56
85
|
|
57
86
|
context "when going to the end of the presentation" do
|
58
87
|
it "should move the last commit" do
|
59
|
-
start_presentation do |commits, presenter|
|
88
|
+
@helper.start_presentation do |commits, presenter|
|
60
89
|
presenter.execute("end")
|
61
|
-
head_position.should eql commits.last.id
|
90
|
+
@helper.head_position.should eql commits.last.id
|
62
91
|
end
|
63
92
|
end
|
64
93
|
end
|
65
94
|
|
66
95
|
context "when going to a specific slide" do
|
67
96
|
it "should checkout the specific commit" do
|
68
|
-
start_presentation do |commits, presenter|
|
97
|
+
@helper.start_presentation do |commits, presenter|
|
69
98
|
presenter.execute("2")
|
70
|
-
head_position.should eql commits[1].id
|
99
|
+
@helper.head_position.should eql commits[1].id
|
71
100
|
end
|
72
101
|
end
|
73
102
|
end
|
74
103
|
|
75
104
|
context "list presentation" do
|
76
105
|
it "should print a list of commits" do
|
77
|
-
start_presentation do |commits, presenter|
|
78
|
-
commits[0]
|
79
|
-
expected_output = commits.join("\n")
|
106
|
+
@helper.start_presentation do |commits, presenter|
|
107
|
+
expected_output = (["*#{commits.first.id[0..9]}, #{commits.first.message}"] + commits[1..-1].map{|commit| "#{commit.id[0..9]}, #{commit.message}"}).join("\n")
|
80
108
|
presentation = presenter.execute("list")
|
81
109
|
presentation.should eql expected_output
|
82
110
|
end
|
@@ -85,7 +113,7 @@ describe "while giving presentation" do
|
|
85
113
|
|
86
114
|
context "when asking for help" do
|
87
115
|
it "should print a list of command and there usage" do
|
88
|
-
start_presentation do |commits, presenter|
|
116
|
+
@helper.start_presentation do |commits, presenter|
|
89
117
|
help_text = <<-EOH
|
90
118
|
Git Presenter Reference
|
91
119
|
|
@@ -95,10 +123,43 @@ end/e: move to end of presentation
|
|
95
123
|
start/s: move to start of presentation
|
96
124
|
list/l : list slides in presentation
|
97
125
|
help/h: display this message
|
126
|
+
!(exclimation mark): execute following in terminal
|
127
|
+
exit: exit from the presentation
|
98
128
|
EOH
|
99
129
|
message = presenter.execute("help")
|
100
130
|
message.should eql help_text
|
101
131
|
end
|
102
132
|
end
|
103
133
|
end
|
134
|
+
|
135
|
+
context "when the slide contains a run command only" do
|
136
|
+
it "should execute the command" do
|
137
|
+
command_line_helper = CommandLineHelper.capture_output
|
138
|
+
@helper.start_presentation("echo hello world") do |commits, presenter|
|
139
|
+
presenter.execute("next")
|
140
|
+
presenter.execute("next")
|
141
|
+
presenter.execute("next").strip.should eql "hello world"
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
context "when the slide has a commit and a run command" do
|
147
|
+
it "should checkout the commit and then execute the command" do
|
148
|
+
command_line_helper = CommandLineHelper.capture_output
|
149
|
+
@helper.start_presentation("echo hello world", 2) do |commits, presenter|
|
150
|
+
presenter.execute("next")
|
151
|
+
presenter.execute("next").should eql "#{commits[2].message}\nhello world\n"
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
context "when executing a command" do
|
157
|
+
it "should run the command in the shell" do
|
158
|
+
command_line_helper = CommandLineHelper.capture_output
|
159
|
+
@helper.start_presentation do |commits, presenter|
|
160
|
+
presenter.execute("!echo hello world")
|
161
|
+
command_line_helper.command_output.strip.should eql "hello world"
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
104
165
|
end
|
@@ -3,29 +3,41 @@ require "spec_helper"
|
|
3
3
|
describe "starting a presentation" do
|
4
4
|
let(:presentation_dir){File.dirname(__FILE__) + "/../../presentation"}
|
5
5
|
|
6
|
+
before do
|
7
|
+
@helper = GitHelper.new(presentation_dir)
|
8
|
+
end
|
9
|
+
|
6
10
|
it "should contian the commits for presentations" do
|
7
|
-
initialise_presentation
|
11
|
+
@helper.initialise_presentation
|
12
|
+
@helper.add_command("echo hello world")
|
8
13
|
Dir.chdir(presentation_dir) do
|
9
14
|
presenter = GitPresenter.start_presentation(".")
|
10
|
-
presenter.
|
15
|
+
presenter.slides.length.should eql 4
|
11
16
|
end
|
12
17
|
end
|
13
18
|
|
14
19
|
it "first commit should be first commit in file" do
|
15
|
-
start_presentation do |commits, presenter|
|
16
|
-
presenter.
|
20
|
+
@helper.start_presentation do |commits, presenter|
|
21
|
+
presenter.slides[0].commit.should eql commits[0].id
|
17
22
|
end
|
18
23
|
end
|
19
24
|
|
20
25
|
it "second commit should be second commit in file" do
|
21
|
-
start_presentation do |commits, presenter|
|
22
|
-
presenter.
|
26
|
+
@helper.start_presentation do |commits, presenter|
|
27
|
+
presenter.slides[1].commit.should eql commits[1].id
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
it "the last commit should be a command" do
|
32
|
+
command = "echo hello world"
|
33
|
+
@helper.start_presentation(command) do |commits, presenter|
|
34
|
+
presenter.slides[3].run.should eql command
|
23
35
|
end
|
24
36
|
end
|
25
37
|
|
26
38
|
it "should have the presentation at first commit" do
|
27
|
-
start_presentation do |commits, presenter|
|
28
|
-
head_position.should eql commits.first.id
|
39
|
+
@helper.start_presentation do |commits, presenter|
|
40
|
+
@helper.head_position.should eql commits.first.id
|
29
41
|
end
|
30
42
|
end
|
31
43
|
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe GitPresenter::Presentation do
|
4
|
+
let(:presentation){ {"slides" => [
|
5
|
+
{"slide" => {"commit" => "0"}},
|
6
|
+
{"slide" => {"commit" => "1"}},
|
7
|
+
{"slide" => {"commit" => "2"}}]
|
8
|
+
}
|
9
|
+
}
|
10
|
+
context "when displaying the command line" do
|
11
|
+
it "should display the current position" do
|
12
|
+
presenter = GitPresenter::Presentation.new(presentation)
|
13
|
+
presenter.status_line.should eql "1/3 >"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
context "when calculating the position" do
|
19
|
+
it "should return the index of the current commit" do
|
20
|
+
presenter = GitPresenter::Presentation.new(presentation)
|
21
|
+
presenter.position.should eql 0
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context "when processing a user command" do
|
26
|
+
def given_command(command)
|
27
|
+
presenter = GitPresenter::Presentation.new(presentation)
|
28
|
+
presenter.command_for(command)
|
29
|
+
end
|
30
|
+
|
31
|
+
context "with bash command" do
|
32
|
+
it { given_command("!echo hello world").should eql :command }
|
33
|
+
end
|
34
|
+
|
35
|
+
context "with next" do
|
36
|
+
it { given_command("next").should eql :next }
|
37
|
+
end
|
38
|
+
|
39
|
+
context "with next" do
|
40
|
+
it { given_command("n").should eql :next }
|
41
|
+
end
|
42
|
+
|
43
|
+
context "with back" do
|
44
|
+
it { given_command("back").should eql :previous }
|
45
|
+
end
|
46
|
+
|
47
|
+
context "with b" do
|
48
|
+
it { given_command("b").should eql :previous }
|
49
|
+
end
|
50
|
+
|
51
|
+
context "with start" do
|
52
|
+
it { given_command("start").should eql :start }
|
53
|
+
end
|
54
|
+
|
55
|
+
context "with s" do
|
56
|
+
it { given_command("s").should eql :start }
|
57
|
+
end
|
58
|
+
|
59
|
+
context "with end" do
|
60
|
+
it { given_command("end").should eql :end }
|
61
|
+
end
|
62
|
+
|
63
|
+
context "with e" do
|
64
|
+
it { given_command("e").should eql :end }
|
65
|
+
end
|
66
|
+
|
67
|
+
context "with list" do
|
68
|
+
it { given_command("list").should eql :list }
|
69
|
+
end
|
70
|
+
|
71
|
+
context "with l" do
|
72
|
+
it { given_command("l").should eql :list }
|
73
|
+
end
|
74
|
+
|
75
|
+
context "with any number" do
|
76
|
+
it { given_command("6").should eql :commit}
|
77
|
+
end
|
78
|
+
|
79
|
+
context "with h" do
|
80
|
+
it { given_command("h").should eql :help}
|
81
|
+
end
|
82
|
+
|
83
|
+
context "with help" do
|
84
|
+
it { given_command("help").should eql :help}
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe GitPresenter::Slide do
|
4
|
+
context "when displaying as string" do
|
5
|
+
it "should write out the commit id and the message" do
|
6
|
+
slide = GitPresenter::Slide.new({"commit" => "012345678901234567890","message" => "message"})
|
7
|
+
slide.to_s.should eql "0123456789, message"
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "execute" do
|
12
|
+
context "when slide has only a run command" do
|
13
|
+
it "should run that command" do
|
14
|
+
command_line_helper = CommandLineHelper.capture_output
|
15
|
+
slide = GitPresenter::Slide.new({"run" => "echo hello world"})
|
16
|
+
slide.execute.strip.should eql "hello world"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context "when slide contains both commit and run message" do
|
21
|
+
it "should checkout the code then run the command" do
|
22
|
+
command_line_helper = CommandLineHelper.capture_output
|
23
|
+
slide = GitPresenter::Slide.new({"commit" => "number", "message" => "checkout", "run" => "echo hello world"})
|
24
|
+
slide.stub(:checkout).and_return("checkout\n")
|
25
|
+
slide.execute.should eql "checkout\nhello world\n"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context "when slide contains only a commit" do
|
30
|
+
it "should checkout the code then run the command" do
|
31
|
+
command_line_helper = CommandLineHelper.capture_output
|
32
|
+
slide = GitPresenter::Slide.new({"commit" => "number", "message" => "checkout"})
|
33
|
+
slide.stub(:checkout).and_return("checkout\n")
|
34
|
+
slide.execute.should eql "checkout\n"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -0,0 +1,18 @@
|
|
1
|
+
class CommandLineHelper
|
2
|
+
|
3
|
+
def self.capture_output
|
4
|
+
command_helper = CommandLineHelper.new
|
5
|
+
command_helper.set_output_to_string_io
|
6
|
+
command_helper
|
7
|
+
end
|
8
|
+
|
9
|
+
def set_output_to_string_io
|
10
|
+
@command_output = StringIO.new
|
11
|
+
$stdout = @command_output
|
12
|
+
end
|
13
|
+
|
14
|
+
def command_output
|
15
|
+
@command_output.string
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
class GitHelper
|
2
|
+
PRESENTATION_DIR = File.expand_path(File.dirname(__FILE__) + '/../../presentation')
|
3
|
+
|
4
|
+
def self.presentation_dir
|
5
|
+
PRESENTATION_DIR
|
6
|
+
end
|
7
|
+
|
8
|
+
def initialize(presentation_dir)
|
9
|
+
@presentation_dir = presentation_dir
|
10
|
+
end
|
11
|
+
|
12
|
+
def initialise_test_repo(presentation_dir, delay)
|
13
|
+
clean_up_repo(presentation_dir)
|
14
|
+
@code_file = "a_file.rb"
|
15
|
+
commits = []
|
16
|
+
Dir.mkdir(presentation_dir)
|
17
|
+
Dir.chdir(presentation_dir) do
|
18
|
+
@git_repo = Grit::Repo.init(".")
|
19
|
+
edit_file_and_commit("initial commit", "a")
|
20
|
+
commits << @git_repo.commits[0]
|
21
|
+
#need to make it sleep for a second.
|
22
|
+
#git is not accurate enough with the speed of the test
|
23
|
+
#to sort correctly
|
24
|
+
sleep 1 if delay
|
25
|
+
edit_file_and_commit("second commit", "b")
|
26
|
+
commits << @git_repo.commits[0]
|
27
|
+
sleep 1 if delay
|
28
|
+
edit_file_and_commit("third commit", "c")
|
29
|
+
commits << @git_repo.commits[0]
|
30
|
+
end
|
31
|
+
commits
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
def edit_file(content)
|
36
|
+
File.open(@code_file, "a") do |file|
|
37
|
+
file.write(content)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def edit_file_and_commit(commit_message, content)
|
42
|
+
edit_file(content)
|
43
|
+
@git_repo.add(".")
|
44
|
+
@git_repo.commit_all(commit_message)
|
45
|
+
end
|
46
|
+
|
47
|
+
def setup_presentation_file(commits)
|
48
|
+
File.open(".presentation", "w") do |file|
|
49
|
+
@commits.each do |commit|
|
50
|
+
file.write(commit.id + "\n")
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def clean_up_repo(dir)
|
56
|
+
`rm -fr #{dir}`
|
57
|
+
end
|
58
|
+
|
59
|
+
def head_position
|
60
|
+
File.open(@presentation_dir + '/.git/HEAD').lines.first.strip
|
61
|
+
end
|
62
|
+
|
63
|
+
def initialise_presentation(delay=false)
|
64
|
+
commits = initialise_test_repo(@presentation_dir, delay)
|
65
|
+
Dir.chdir(@presentation_dir) do
|
66
|
+
git_presentation = GitPresenter.initialise_presentation(".")
|
67
|
+
yaml = YAML::parse(File.open(File.join(@presentation_dir, ".presentation"))).to_ruby
|
68
|
+
yield(commits, yaml) if block_given?
|
69
|
+
end
|
70
|
+
commits
|
71
|
+
end
|
72
|
+
|
73
|
+
def start_presentation(command="", add_command_to_commit=nil)
|
74
|
+
commits = initialise_presentation(true)
|
75
|
+
Dir.chdir(@presentation_dir) do
|
76
|
+
add_command(command, add_command_to_commit) unless command.empty?
|
77
|
+
presenter = GitPresenter.start_presentation(".")
|
78
|
+
yield(commits, presenter) if block_given?
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def add_command(command, add_command_to_commit=nil)
|
83
|
+
Dir.chdir(PRESENTATION_DIR) do
|
84
|
+
presentation = YAML.parse(File.open(".presentation")).to_ruby
|
85
|
+
if !add_command_to_commit.nil?
|
86
|
+
presentation["slides"][add_command_to_commit]["slide"]["run"] = command
|
87
|
+
else
|
88
|
+
presentation["slides"] << {"slide" => {"run" => command}}
|
89
|
+
end
|
90
|
+
File.open(".presentation", "w") do |file|
|
91
|
+
file.write(presentation.to_yaml)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: git_presenter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-03-
|
12
|
+
date: 2012-03-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: grit
|
16
|
-
requirement: &
|
16
|
+
requirement: &70214612260380 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '2.4'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70214612260380
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rspec
|
27
|
-
requirement: &
|
27
|
+
requirement: &70214612259060 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '2.7'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70214612259060
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: bundler
|
38
|
-
requirement: &
|
38
|
+
requirement: &70214612272960 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70214612272960
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: jeweler
|
49
|
-
requirement: &
|
49
|
+
requirement: &70214612265840 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '1.6'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70214612265840
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: rcov
|
60
|
-
requirement: &
|
60
|
+
requirement: &70214612322680 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ~>
|
@@ -65,7 +65,7 @@ dependencies:
|
|
65
65
|
version: '0.9'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70214612322680
|
69
69
|
description: Code presentation tool using git
|
70
70
|
email: pythonandchips@gmail.com
|
71
71
|
executables:
|
@@ -76,6 +76,7 @@ extra_rdoc_files:
|
|
76
76
|
- README.markdown
|
77
77
|
files:
|
78
78
|
- .rspec
|
79
|
+
- .travis.yml
|
79
80
|
- Gemfile
|
80
81
|
- Gemfile.lock
|
81
82
|
- LICENSE.txt
|
@@ -85,13 +86,19 @@ files:
|
|
85
86
|
- bin/git-presenter
|
86
87
|
- git_presenter.gemspec
|
87
88
|
- lib/git_presenter.rb
|
89
|
+
- lib/git_presenter/parser.rb
|
90
|
+
- lib/git_presenter/presentation.rb
|
91
|
+
- lib/git_presenter/slide.rb
|
92
|
+
- lib/git_presenter/writer.rb
|
88
93
|
- spec/integration/initialize_presentation_spec.rb
|
89
94
|
- spec/integration/moving_through_presentation_spec.rb
|
90
|
-
- spec/integration/processing_user_command_spec.rb
|
91
95
|
- spec/integration/start_presentation_spec.rb
|
92
|
-
- spec/
|
96
|
+
- spec/lib/git_presenter/presentation_spec.rb
|
97
|
+
- spec/lib/git_presenter/slide_spec.rb
|
98
|
+
- spec/lib/git_presenter/writer_spec.rb
|
93
99
|
- spec/spec_helper.rb
|
94
|
-
- spec/support/
|
100
|
+
- spec/support/command_line_helper.rb
|
101
|
+
- spec/support/git_helpers.rb
|
95
102
|
homepage: http://github.com/pythonandchips/git-presenter
|
96
103
|
licenses:
|
97
104
|
- MIT
|
@@ -107,7 +114,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
107
114
|
version: '0'
|
108
115
|
segments:
|
109
116
|
- 0
|
110
|
-
hash:
|
117
|
+
hash: 2885974692794376119
|
111
118
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
119
|
none: false
|
113
120
|
requirements:
|
@@ -1,61 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe "when receiving a user command" do
|
4
|
-
|
5
|
-
def given_command(command)
|
6
|
-
presenter = GitPresenter.new([])
|
7
|
-
presenter.command_for(command)
|
8
|
-
end
|
9
|
-
|
10
|
-
context "with next" do
|
11
|
-
it { given_command("next").should eql :next }
|
12
|
-
end
|
13
|
-
|
14
|
-
context "with next" do
|
15
|
-
it { given_command("n").should eql :next }
|
16
|
-
end
|
17
|
-
|
18
|
-
context "with back" do
|
19
|
-
it { given_command("back").should eql :previous }
|
20
|
-
end
|
21
|
-
|
22
|
-
context "with b" do
|
23
|
-
it { given_command("b").should eql :previous }
|
24
|
-
end
|
25
|
-
|
26
|
-
context "with start" do
|
27
|
-
it { given_command("start").should eql :start }
|
28
|
-
end
|
29
|
-
|
30
|
-
context "with s" do
|
31
|
-
it { given_command("s").should eql :start }
|
32
|
-
end
|
33
|
-
|
34
|
-
context "with end" do
|
35
|
-
it { given_command("end").should eql :end }
|
36
|
-
end
|
37
|
-
|
38
|
-
context "with e" do
|
39
|
-
it { given_command("e").should eql :end }
|
40
|
-
end
|
41
|
-
|
42
|
-
context "with list" do
|
43
|
-
it { given_command("list").should eql :list }
|
44
|
-
end
|
45
|
-
|
46
|
-
context "with l" do
|
47
|
-
it { given_command("l").should eql :list }
|
48
|
-
end
|
49
|
-
|
50
|
-
context "with any number" do
|
51
|
-
it { given_command("6").should eql :commit}
|
52
|
-
end
|
53
|
-
|
54
|
-
context "with h" do
|
55
|
-
it { given_command("h").should eql :help}
|
56
|
-
end
|
57
|
-
|
58
|
-
context "with help" do
|
59
|
-
it { given_command("help").should eql :help}
|
60
|
-
end
|
61
|
-
end
|
@@ -1,65 +0,0 @@
|
|
1
|
-
def initialise_test_repo(presentation_dir, delay)
|
2
|
-
clean_up_repo(presentation_dir)
|
3
|
-
code_file = "a_file.rb"
|
4
|
-
commits = []
|
5
|
-
Dir.mkdir(presentation_dir)
|
6
|
-
Dir.chdir(presentation_dir) do
|
7
|
-
git_repo = Grit::Repo.init(".")
|
8
|
-
File.open(code_file, "w") do |file|
|
9
|
-
file.write("a")
|
10
|
-
end
|
11
|
-
git_repo.add(".")
|
12
|
-
git_repo.commit_all("initial commit")
|
13
|
-
commits << git_repo.commits[0]
|
14
|
-
#need to make it sleep for a second.
|
15
|
-
#git is not accurate enough with the speed of the test
|
16
|
-
#to sort correctly
|
17
|
-
sleep 1 if delay
|
18
|
-
File.open(code_file, "a") do |file|
|
19
|
-
file.write("b")
|
20
|
-
end
|
21
|
-
git_repo.commit_all("second commit")
|
22
|
-
commits << git_repo.commits[0]
|
23
|
-
sleep 1 if delay
|
24
|
-
File.open(code_file, "a") do |file|
|
25
|
-
file.write("c")
|
26
|
-
end
|
27
|
-
git_repo.commit_all("third commit")
|
28
|
-
commits << git_repo.commits[0]
|
29
|
-
end
|
30
|
-
commits
|
31
|
-
end
|
32
|
-
|
33
|
-
def setup_presentation_file(commits)
|
34
|
-
File.open(".presentation", "w") do |file|
|
35
|
-
@commits.each do |commit|
|
36
|
-
file.write(commit.id + "\n")
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
def clean_up_repo(dir)
|
42
|
-
`rm -fr #{dir}`
|
43
|
-
end
|
44
|
-
|
45
|
-
def head_position
|
46
|
-
File.open(presentation_dir + '/.git/HEAD').lines.first.strip
|
47
|
-
end
|
48
|
-
|
49
|
-
def initialise_presentation(delay=false)
|
50
|
-
commits = initialise_test_repo(presentation_dir, delay)
|
51
|
-
Dir.chdir(presentation_dir) do
|
52
|
-
git_presentation = GitPresenter.initialise_presentation(".")
|
53
|
-
file = File.open(File.join(presentation_dir, ".presentation"))
|
54
|
-
yield(commits, file) if block_given?
|
55
|
-
end
|
56
|
-
commits
|
57
|
-
end
|
58
|
-
|
59
|
-
def start_presentation
|
60
|
-
commits = initialise_presentation(true)
|
61
|
-
Dir.chdir(presentation_dir) do
|
62
|
-
presenter = GitPresenter.start_presentation(".")
|
63
|
-
yield(commits, presenter) if block_given?
|
64
|
-
end
|
65
|
-
end
|