Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-shell
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
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-shell
Commits
9a407166
Commit
9a407166
authored
Feb 06, 2013
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update hook and support for protected branches
parent
96454ac5
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
58 additions
and
8 deletions
+58
-8
hooks/post-receive
hooks/post-receive
+0
-1
hooks/update
hooks/update
+12
-0
lib/gitlab_net.rb
lib/gitlab_net.rb
+1
-1
lib/gitlab_projects.rb
lib/gitlab_projects.rb
+9
-3
lib/gitlab_shell.rb
lib/gitlab_shell.rb
+1
-3
lib/gitlab_update.rb
lib/gitlab_update.rb
+29
-0
support/rewrite-hooks.sh
support/rewrite-hooks.sh
+6
-0
No files found.
hooks/post-receive
View file @
9a407166
#!/usr/bin/env bash
#!/usr/bin/env bash
# Version 4.1
# This file was placed here by GitLab. It makes sure that your pushed commits
# This file was placed here by GitLab. It makes sure that your pushed commits
# will be processed properly.
# will be processed properly.
...
...
hooks/update
0 → 100755
View file @
9a407166
#!/usr/bin/env ruby
# This file was placed here by GitLab. It makes sure that your pushed commits
# will be processed properly.
refname
=
ARGV
[
0
]
key_id
=
ENV
[
'GL_USER'
]
repo_path
=
`pwd`
require_relative
'../lib/gitlab_update'
GitlabUpdate
.
new
(
repo_path
,
key_id
,
refname
).
exec
lib/gitlab_net.rb
View file @
9a407166
...
@@ -9,7 +9,7 @@ class GitlabNet
...
@@ -9,7 +9,7 @@ class GitlabNet
project_name
=
project_name
.
gsub
(
/\.git$/
,
""
)
project_name
=
project_name
.
gsub
(
/\.git$/
,
""
)
key_id
=
key
.
gsub
(
"key-"
,
""
)
key_id
=
key
.
gsub
(
"key-"
,
""
)
url
=
"
#{
host
}
/allowed?
project=
#{
project_name
}
&key_id=
#{
key_id
}
&action=
#{
cmd
}
&ref=
#{
ref
}
"
url
=
"
#{
host
}
/allowed?
key_id=
#{
key_id
}
&action=
#{
cmd
}
&ref=
#{
ref
}
&project=
#{
project_name
}
"
resp
=
get
(
url
)
resp
=
get
(
url
)
...
...
lib/gitlab_projects.rb
View file @
9a407166
...
@@ -10,7 +10,6 @@ class GitlabProjects
...
@@ -10,7 +10,6 @@ class GitlabProjects
@project_name
=
ARGV
.
shift
@project_name
=
ARGV
.
shift
@repos_path
=
GitlabConfig
.
new
.
repos_path
@repos_path
=
GitlabConfig
.
new
.
repos_path
@full_path
=
File
.
join
(
@repos_path
,
@project_name
)
@full_path
=
File
.
join
(
@repos_path
,
@project_name
)
@hook_path
=
File
.
join
(
ROOT_PATH
,
'hooks'
,
'post-receive'
)
end
end
def
exec
def
exec
...
@@ -27,17 +26,24 @@ class GitlabProjects
...
@@ -27,17 +26,24 @@ class GitlabProjects
def
add_project
def
add_project
FileUtils
.
mkdir_p
(
full_path
,
mode:
0770
)
FileUtils
.
mkdir_p
(
full_path
,
mode:
0770
)
cmd
=
"cd
#{
full_path
}
&& git init --bare &&
ln -s
#{
@hook_path
}
#{
full_path
}
/hooks/post-receive
"
cmd
=
"cd
#{
full_path
}
&& git init --bare &&
#{
create_hooks_cmd
}
"
system
(
cmd
)
system
(
cmd
)
end
end
def
create_hooks_cmd
pr_hook_path
=
File
.
join
(
ROOT_PATH
,
'hooks'
,
'post-receive'
)
up_hook_path
=
File
.
join
(
ROOT_PATH
,
'hooks'
,
'update'
)
"ln -s
#{
pr_hook_path
}
#{
full_path
}
/hooks/post-receive && ln -s
#{
up_hook_path
}
#{
full_path
}
/hooks/update"
end
def
rm_project
def
rm_project
FileUtils
.
rm_rf
(
full_path
)
FileUtils
.
rm_rf
(
full_path
)
end
end
def
import_project
def
import_project
dir
=
@project_name
.
match
(
/[a-zA-Z\.\_\-]+\.git$/
).
to_s
dir
=
@project_name
.
match
(
/[a-zA-Z\.\_\-]+\.git$/
).
to_s
cmd
=
"cd
#{
@repos_path
}
&& git clone --bare
#{
@project_name
}
#{
dir
}
&&
ln -s
#{
@hook_path
}
#{
@repos_path
}
/
#{
dir
}
/hooks/post-receive
"
cmd
=
"cd
#{
@repos_path
}
&& git clone --bare
#{
@project_name
}
#{
dir
}
&&
#{
create_hooks_cmd
}
"
system
(
cmd
)
system
(
cmd
)
end
end
end
end
lib/gitlab_shell.rb
View file @
9a407166
...
@@ -49,9 +49,7 @@ class GitlabShell
...
@@ -49,9 +49,7 @@ class GitlabShell
end
end
def
validate_access
def
validate_access
@ref_name
=
'master'
# just hardcode it cause we dont know ref
api
.
allowed?
(
@git_cmd
,
@repo_name
,
@key_id
,
'_any'
)
api
.
allowed?
(
@git_cmd
,
@repo_name
,
@key_id
,
@ref_name
)
end
end
def
api
def
api
...
...
lib/gitlab_update.rb
0 → 100644
View file @
9a407166
require_relative
'gitlab_init'
require_relative
'gitlab_net'
class
GitlabUpdate
def
initialize
(
repo_path
,
key_id
,
refname
)
@repo_name
=
repo_path
@repo_name
.
gsub!
(
GitlabConfig
.
new
.
repos_path
.
to_s
,
""
)
@repo_name
.
gsub!
(
/.git$/
,
""
)
@repo_name
.
gsub!
(
/^\//
,
""
)
@key_id
=
key_id
@refname
=
/refs\/heads\/([\w\.-]+)/
.
match
(
refname
).
to_a
.
last
end
def
exec
if
api
.
allowed?
(
'git-receive-pack'
,
@repo_name
,
@key_id
,
@refname
)
exit
0
else
puts
"GitLab: You are not allowed to access
#{
@refname
}
! "
exit
1
end
end
protected
def
api
GitlabNet
.
new
end
end
support/rewrite-hooks.sh
View file @
9a407166
...
@@ -15,7 +15,10 @@ do
...
@@ -15,7 +15,10 @@ do
then
then
project_hook
=
"
$src
/
$dir
/hooks/post-receive"
project_hook
=
"
$src
/
$dir
/hooks/post-receive"
gitolite_hook
=
"/home/git/gitlab-shell/hooks/post-receive"
gitolite_hook
=
"/home/git/gitlab-shell/hooks/post-receive"
ln
-s
-f
$gitolite_hook
$project_hook
project_hook
=
"
$src
/
$dir
/hooks/update"
gitolite_hook
=
"/home/git/gitlab-shell/hooks/update"
ln
-s
-f
$gitolite_hook
$project_hook
ln
-s
-f
$gitolite_hook
$project_hook
else
else
for
subdir
in
`
ls
"
$src
/
$dir
/"
`
for
subdir
in
`
ls
"
$src
/
$dir
/"
`
...
@@ -23,7 +26,10 @@ do
...
@@ -23,7 +26,10 @@ do
if
[
-d
"
$src
/
$dir
/
$subdir
"
]
&&
[[
"
$subdir
"
=
~ ^.
*
.git
$
]]
;
then
if
[
-d
"
$src
/
$dir
/
$subdir
"
]
&&
[[
"
$subdir
"
=
~ ^.
*
.git
$
]]
;
then
project_hook
=
"
$src
/
$dir
/
$subdir
/hooks/post-receive"
project_hook
=
"
$src
/
$dir
/
$subdir
/hooks/post-receive"
gitolite_hook
=
"/home/git/gitlab-shell/hooks/post-receive"
gitolite_hook
=
"/home/git/gitlab-shell/hooks/post-receive"
ln
-s
-f
$gitolite_hook
$project_hook
project_hook
=
"
$src
/
$dir
/
$subdir
/hooks/update"
gitolite_hook
=
"/home/git/gitlab-shell/hooks/update"
ln
-s
-f
$gitolite_hook
$project_hook
ln
-s
-f
$gitolite_hook
$project_hook
fi
fi
done
done
...
...
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