Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
443e23e6
Commit
443e23e6
authored
Sep 05, 2012
by
Robert Speicher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Repository#discover_default_branch and add it to PushObserver
parent
f06d98e9
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
7 deletions
+33
-7
app/roles/push_observer.rb
app/roles/push_observer.rb
+12
-4
app/roles/repository.rb
app/roles/repository.rb
+21
-3
No files found.
app/roles/push_observer.rb
View file @
443e23e6
# Includes methods for handling Git Push events
#
# Triggered by PostReceive job
module
PushObserver
def
observe_push
(
oldrev
,
newrev
,
ref
,
user
)
data
=
post_receive_data
(
oldrev
,
newrev
,
ref
,
user
)
...
...
@@ -84,11 +87,10 @@ module PushObserver
data
end
# This method will be called after each post receive
# and only if user present in gitlab.
# All callbacks for post receive should be placed here
# This method will be called after each post receive and only if the provided
# user is present in GitLab.
#
# All callbacks for post receive should be placed here.
def
trigger_post_receive
(
oldrev
,
newrev
,
ref
,
user
)
# Create push event
self
.
observe_push
(
oldrev
,
newrev
,
ref
,
user
)
...
...
@@ -101,5 +103,11 @@ module PushObserver
# Create satellite
self
.
satellite
.
create
unless
self
.
satellite
.
exists?
# Discover the default branch, but only if it hasn't already been set to
# something else
if
default_branch
.
nil?
update_attributes
(
default_branch:
discover_default_branch
)
end
end
end
app/roles/repository.rb
View file @
443e23e6
...
...
@@ -94,6 +94,24 @@ module Repository
end
.
sort_by
(
&
:name
)
end
# Discovers the default branch based on the repository's available branches
#
# - If no branches are present, returns nil
# - If one branch is present, returns its name
# - If two or more branches are present, returns the one that has a name
# matching root_ref (default_branch or 'master' if default_branch is nil)
def
discover_default_branch
branches
=
heads
.
collect
(
&
:name
)
if
branches
.
length
==
0
nil
elsif
branches
.
length
==
1
branches
.
first
else
branches
.
select
{
|
v
|
v
==
root_ref
}.
first
end
end
def
has_commits?
!!
commit
end
...
...
@@ -102,7 +120,7 @@ module Repository
default_branch
||
"master"
end
def
root_ref?
branch
def
root_ref?
(
branch
)
root_ref
==
branch
end
...
...
@@ -111,7 +129,7 @@ module Repository
# Already packed repo archives stored at
# app_root/tmp/repositories/project_name/project_name-commit-id.tag.gz
#
def
archive_repo
ref
def
archive_repo
(
ref
)
ref
=
ref
||
self
.
root_ref
commit
=
self
.
commit
(
ref
)
return
nil
unless
commit
...
...
@@ -138,6 +156,6 @@ module Repository
end
def
http_url_to_repo
http_url
=
[
Gitlab
.
config
.
url
,
"/"
,
path
,
".git"
].
join
()
http_url
=
[
Gitlab
.
config
.
url
,
"/"
,
path
,
".git"
].
join
(
''
)
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment