Skip to content

Commit

Permalink
Introduced full branching support.
Browse files Browse the repository at this point in the history
Some other minor improvements.
  • Loading branch information
Alwahsh committed Apr 13, 2015
1 parent fe6dd21 commit e79c162
Show file tree
Hide file tree
Showing 17 changed files with 479 additions and 184 deletions.
7 changes: 3 additions & 4 deletions app/assets/stylesheets/_form.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@
font-size: 1em;
margin-bottom: 0.5em;
}
input[type="text"],input[type="email"],input[type="password"],textarea{
input[type="text"],input[type="email"],input[type="password"],input[type="file"],textarea,select{
margin-bottom: 0.5em;
padding: 1em 0;
text-indent: 1em;
width: 100%;
padding: 1em 1em;
width: 95%;
display: block;
border-style: none;
@include border-radius(0.25em);
Expand Down
15 changes: 15 additions & 0 deletions app/assets/stylesheets/_project.scss
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,21 @@
}
}
}
section.list{
div{
padding: 1em;
box-shadow:0 0 0.3em 0 $dark_geometry_gray;
a{
font-size: 1.2em;
color: $map_blue;
background-color: $geometry_gray;
}
a:hover{
background-color: $dark_geometry_gray;
font-weight: 700;
}
}
}
}
}
}
Expand Down
63 changes: 39 additions & 24 deletions app/controllers/projects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,32 +96,29 @@ def unfollow
redirect_to user_project_path @project.user, @project
end

def tree_at(revision, path)
barerepo = @project.barerepo
tree = Rugged::Commit.lookup(barerepo, revision).tree
path == '/' ? tree.oid : tree.path(path)[:oid]
end

# GET /user/project/blob/branch_or_commit_oid/destination
def blob
barerepo = @project.barerepo
oid = params[:oid]
@branch = barerepo.branches[oid]
oid = barerepo.branches[oid].target.oid if @branch
@blob = @project.blob oid, params[:destination]
@enc_blob_text = Base64.encode64 @blob.text
oid = @project.branch_commit(params[:oid]).oid
blob = @project.blob oid, params[:destination]
@image = { data: blob.text, name: params[:destination] }
@comments = Comment.where(
polycomment_type: 'blob',
polycomment_id: @blob.oid
polycomment_id: blob.oid
)
@comments = pg @comments, 10
@comment = Comment.new
@ajax = params[:page].nil? || params[:page] == 1
end

# GET /user/project/branches
def branches
@branches = @project.barerepo.branches
end

def show
@images = []
barerepo = @project.barerepo
@branches = barerepo.branches
unless barerepo.empty?
headtree = barerepo.lookup barerepo.last_commit.tree_id
# TODO: what if there are trees inside this tree?
Expand Down Expand Up @@ -154,20 +151,20 @@ def network
# status (files added/removed in each commit)
# full (list all files in that commit as they list)

# GET /commits/branch
# GET /commits/branch_or_SHA
def commits
branch = params[:branch] || 'master'
if @project.barerepo.empty?
flash[:notice] = 'This project has no commits.'
else
@commits = Rugged::Walker.new @project.barerepo
@commits.push @project.barerepo.branches[branch].target
@commits.push @project.branch_commit params[:oid]
end
end

# GET /commit/commit_id
def commit
@images = []
@oid = params[:commit_id]
commit = @project.commit params[:commit_id]
redirect_to(user_project_path(@project.user, @project)) unless commit
barerepo = @project.barerepo
Expand All @@ -185,21 +182,31 @@ def commit
@comments = pg @comments, 10
@comment = Comment.new
@id = commit.oid
@tree = commit.tree_id
end

# POST /user/project/create_branch
# TODO: to be visited after adding cancancan.
def create_branch
@branch = @project.create_branch params[:branch_name]
if @branch
flash[:notice] = "Successfully created #{params[:branch_name]}!"
redirect_to project_tree_path @project, @branch.name
else
flash[:alert] = 'Something went wrong, the branch was not created!'
redirect_to project_branches_path @project
end
end

# GET /tree/tree_id
def tree
@images = []
tree = @project.tree params[:tree_id]
@oid = params[:oid]
tree = @project.branch_tree @oid
redirect_to(user_project_path(@project.user, @project)) unless tree
barerepo = @project.barerepo
tree.each do |blob|
link = File.join @project.urlbase, 'master', blob[:name]
data = barerepo.read(blob[:oid]).data
@images.push({ link: link,
data: data,
name: blob[:name] })
@images.push({ data: data, name: blob[:name] })
end
@comments = Comment.where(
polycomment_type: 'commit',
Expand Down Expand Up @@ -231,6 +238,11 @@ def file_history
end

def newfile
@cur = params[:oid] || 'master'
@all = @project.barerepo.branches
return if @project.branch? params[:oid]
flash[:alert] = 'You need to be on a valid branch to upload a new file'
redirect_to :back
end

def update
Expand All @@ -239,21 +251,24 @@ def update
# TODO: allow uploads/updates of only supported images.

def file_upload
branch = params[:branch] || 'master'
if params[:file]
if user_signed_in? && @project.add_images(
params[:branch] || 'master',
branch,
params[:file],
@user.git_author_params
)
sentence = view_context.pluralize(params[:file].size, 'image')
flash[:notice] = "Successfully added #{sentence}! How sparkly!"
redirect_to project_tree_path(@project, branch)
else
flash[:alert] = "An error prevented your #{sentence} from being saved"
redirect_to project_newfile_path(@project, branch)
end
else
flash[:alert] = 'No image selected!'
redirect_to project_newfile_path(@project, branch)
end
redirect_to user_project_path @project.user, @project
end

def file_update
Expand Down
40 changes: 26 additions & 14 deletions app/helpers/paths_helper.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
module PathsHelper
def project_branches_path(project)
branches_user_project_path project.user, project, project.uniqueurl
end

def project_issues_path(project)
user_project_issues_path project.user, project, params[:xid]
user_project_issues_path project.user, project, project.uniqueurl
end

def issue_path(issue)
user_project_issue_path(
issue.project.user,
issue.project,
params[:xid],
issue.project.uniqueurl,
issue
)
end
Expand All @@ -16,7 +20,7 @@ def close_issue_path(issue)
close_user_project_issue_path(
issue.project.user,
issue.project,
params[:xid],
issue.project.uniqueurl,
issue
)
end
Expand All @@ -25,45 +29,53 @@ def reopen_issue_path(issue)
reopen_user_project_issue_path(
issue.project.user,
issue.project,
params[:xid],
issue.project.uniqueurl,
issue
)
end

def project_commits_path(project)
commits_user_project_path project.user, project, params[:xid]
def project_commits_path(project, oid = nil)
commits_user_project_path project.user, project, project.uniqueurl, oid
end

def project_network_path(project)
network_user_project_path project.user, project, params[:xid]
network_user_project_path project.user, project, project.uniqueurl
end

def project_newfile_path(project)
newfile_user_project_path project.user, project, params[:xid]
def project_newfile_path(project, branch)
newfile_user_project_path project.user, project, project.uniqueurl, branch
end

def project_fork_path(project)
fork_user_project_path project.user, project, params[:xid]
fork_user_project_path project.user, project, project.uniqueurl
end

def project_settings_path(project)
settings_user_project_path project.user, project, params[:xid]
settings_user_project_path project.user, project, project.uniqueurl
end

def project_follow_path(project)
follow_user_project_path project.user, project, params[:xid]
follow_user_project_path project.user, project, project.uniqueurl
end

def project_unfollow_path(project)
unfollow_user_project_path project.user, project, params[:xid]
unfollow_user_project_path project.user, project, project.uniqueurl
end

def project_create_branch_path(project)
create_branch_user_project_path project.user, project, project.uniqueurl
end

def project_tree_path(project, oid)
tree_user_project_path(project.user, project, project.uniqueurl, oid)
end

def project_blob_path(project, destination, branch)
branch ||= 'master'
blob_user_project_path(
project.user,
project,
params[:xid],
project.uniqueurl,
branch,
destination
)
Expand Down
38 changes: 29 additions & 9 deletions app/models/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,6 @@ def followed_by?(user)
ProjectFollower.following? user, self
end

def last_updated
repo = barerepo
repo.head.target.time
end

def deletefiles
FileUtils.rm_rf data_path
end
Expand All @@ -64,10 +59,6 @@ def urlbase
uniqueurl.to_s).gsub(/\/$/, '')
end

def issues_url
File.join urlbase, 'issues'
end

def barerepo
Rugged::Repository.new barerepopath
end
Expand Down Expand Up @@ -123,6 +114,35 @@ def blob(oid, destination)
res
end

def branch_commit(id)
res = barerepo.branches[id] if id
return res.target if res
commit id
end

def branch?(branch)
return true unless branch
!barerepo.branches[branch].nil?
end

# Returns the target tree of the branch specified in id.
# If no such branch exists, returns the tree of the given commit id.
def branch_tree(id)
res = branch_commit id
return res.tree if res
end

# Creates a new branch from master.
def create_branch(name)
begin
res = satelliterepo.create_branch(name)
rescue
return nil
end
pushtobare name
res
end

# Generates a thumbnail for a commit in the appropriate place.
def generate_thumbnail(image_path, commit_id)
thumb_size = Glitter::Application.config.thumbnail_geometry
Expand Down
3 changes: 2 additions & 1 deletion app/views/dashboard/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
%input{ type: 'submit', value: 'Create first project!' }
- else
.guide
%p Looks like you're going great,
%p
Looks like you're going great,
congrats! Get noticed by updating your profile.
%form{ action: '/users/edit' }
%input{ type: 'submit', value: 'Get me started!' }
Expand Down
4 changes: 4 additions & 0 deletions app/views/projects/_empty_project.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.guide
%p Submit your design work on this project to start collaborating.
%form{ action: project_newfile_path(@project, params[:oid]) }
%input{ type: 'submit', value: 'Add first file!' }
8 changes: 3 additions & 5 deletions app/views/projects/_images.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
- if @images.empty?
- if user_signed_in?
- if current_user.id == @project.user.id
.guide
%p Submit your design work on this project to start collaborating.
%form{ action: File.join(@project.name, 'newfile') }
%input{ type: 'submit', value: 'Add first file!' }
= render 'empty_project'
- else
.guide
%p
Expand All @@ -24,7 +21,8 @@
- @images.each do |image|
%div
%p{ title: image[:name] }
= link_to(image_tag(image[:url]), project_blob_path(@project, image[:name], @branch), id: image[:name])
= link_to project_blob_path(@project, image[:name], @branch), id: image[:name] do
= image_tag(image[:url])
- if user_signed_in? && current_user.id == @project.user.id
%div
= form_tag file_upload_user_project_path(@project.user,
Expand Down
7 changes: 6 additions & 1 deletion app/views/projects/_project_header.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,9 @@
%span.badge.author PARENT
- else
%span.badge.author FORK
= render partial: 'forked_from', locals: { project: @project }
= render partial: 'forked_from', locals: { project: @project }

- if params[:oid] && params[:oid] != 'master'
%p
@
= params[:oid]
Loading

0 comments on commit e79c162

Please sign in to comment.