Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 1 addition & 23 deletions lib/views/status.erb
Original file line number Diff line number Diff line change
Expand Up @@ -289,29 +289,7 @@
<% end%>
</form>
</div>
<% @graph_branches.each do |branch_hash| %>
<h4 class="p-4"><%= branch_hash[:branch] %></h4>
<code class="bg-dark text-white p-3">
<% branch_hash[:log].reverse.each do |commit| %>
<div>
<span class="commit">
<button class="btn btn-link sha"><%= commit[:sha] %></button>
</span>
— <%= commit[:date].strftime("%a, %d %b %Y, %H:%M %z") %> (<%= commit[:formatted_date] %> ago)
<% heads = "(#{commit[:heads].join(", ")})" if !commit[:heads].empty? %>
<% if commit[:heads].include? @current_branch %>
<%= heads.gsub(@current_branch, '<span class="text-success">HEAD</span> --> ' + @current_branch) %>
<% else %>
<%= heads %>
<% end %>
<div>
&emsp; | <%= commit[:message] + " - " + commit[:author] %>
</div>
</div>
<% end %>
</code>
<hr>
<% end %>
<pre class="bg-dark text-white p-3"><%= @cli_graph_interactive %></pre>
</div>
</div>
</div>
Expand Down
1 change: 1 addition & 0 deletions lib/web_git.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class Server < Sinatra::Base

graph = WebGit::Graph.new(git)
@graph_hash = graph.to_hash
@cli_graph_interactive = graph.cli_graph
@graph_branches = @graph_hash.sort do |branch_a, branch_b|
branch_b[:log].last[:date] <=> branch_a[:log].last[:date]
end
Expand Down
25 changes: 25 additions & 0 deletions lib/web_git/graph.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,31 @@ def to_hash
@full_list
end

def self.project_root
if defined?(Rails)
return Rails.root
end

if defined?(Bundler)
return Bundler.root
end

Dir.pwd
end

def cli_graph
Dir.chdir(Graph.project_root) do
@cli_graph = `git log --oneline --decorate --graph --all`
all_commits = `git log --all --format=format:%H`.split("\n").map{|a| a.slice(0,7)}

all_commits.each do |sha|
sha_button = "<span class=\"commit\"><button class=\"btn btn-link sha\">#{sha}</button></span>"
@cli_graph.gsub!(sha, sha_button)
end
end
@cli_graph
end

def has_untracked_changes?
@git.diff.size > 0
end
Expand Down