Browse files

added branch history and basic revert which mostly works well

  • Loading branch information...
1 parent 07441fa commit 0876ca32bb4331a451e3d2ebc52405f8414ed822 @schacon schacon committed Mar 7, 2008
Showing with 40 additions and 6 deletions.
  1. +14 −0 git-wiki.rb
  2. +10 −6 page.rb
  3. +15 −0 views/branch_history.erb
  4. +1 −0 views/layout.erb
View
14 git-wiki.rb
@@ -112,6 +112,20 @@ def touchfile
redirect '/' + HOMEPAGE
end
+get '/a/history' do
+ @history = $repo.log
+ show :branch_history, "Branch History"
+end
+
+get '/a/revert_branch/:sha' do
+ $repo.with_temp_index do
+ $repo.read_tree params[:sha]
+ $repo.checkout_index
+ $repo.commit('reverted branch')
+ end
+ redirect '/a/history'
+end
+
get '/a/merge_branch/:branch' do
$repo.merge(params[:branch])
redirect '/a/branches'
View
16 page.rb
@@ -23,7 +23,7 @@ def branch_name
end
def updated_at
- commit.committer_date
+ commit.committer_date rescue Time.now
end
def raw_body
@@ -71,12 +71,16 @@ def previous_commit
end
def next_commit
- if (self.history.first.sha == self.commit.sha)
+ begin
+ if (self.history.first.sha == self.commit.sha)
+ @next_commit ||= nil
+ else
+ matching_index = nil
+ history.each_with_index { |c, i| matching_index = i if c.sha == self.commit.sha }
+ @next_commit ||= history.to_a[matching_index - 1]
+ end
+ rescue
@next_commit ||= nil
- else
- matching_index = nil
- history.each_with_index { |c, i| matching_index = i if c.sha == self.commit.sha }
- @next_commit ||= history.to_a[matching_index - 1]
end
end
View
15 views/branch_history.erb
@@ -0,0 +1,15 @@
+<h1>Branch History</h1>
+
+<table width="100%">
+<% @history.each do |commit| %>
+ <tr>
+ <td><code><%= commit.sha[0, 8] %></code></td>
+ <td><%= commit.date %></td>
+ <td><%= commit.message %></td>
+ <td><%= commit.name %></td>
+ <% if commit != @history.first %>
+ <td><a href="/a/revert_branch/<%= commit.sha %>">revert</td>
+ <% end %>
+ </tr>
+<% end %>
+</table>
View
1 views/layout.erb
@@ -12,6 +12,7 @@
<li><strong><%= $repo.current_branch %></strong></li>
<li><a href="/" class="nav_link">home</a></li>
<li><a href="/a/branches" class="nav_link">branches</a></li>
+ <li><a href="/a/history" class="nav_link">history</a></li>
<li><a href="/_list" class="nav_link">pages</a></li>
<li><a href="/a/tarball" class="nav_link">tarball</a></li>
</ul>

0 comments on commit 0876ca3

Please sign in to comment.