[sysadmin-bin] Refusing incoming pushes should happen directly at the run-git-or-special-cmd layer



commit 5e9b639cf0f58d5f70f6932220e256ce16d55189
Author: Andrea Veri <averi redhat com>
Date:   Wed May 30 14:49:12 2018 +0200

    Refusing incoming pushes should happen directly at the run-git-or-special-cmd layer

 git/gnome-pre-receive  | 17 -----------------
 run-git-or-special-cmd | 27 +++++++++++++++++++++------
 2 files changed, 21 insertions(+), 23 deletions(-)
---
diff --git a/git/gnome-pre-receive b/git/gnome-pre-receive
index cd95555..3e6458b 100755
--- a/git/gnome-pre-receive
+++ b/git/gnome-pre-receive
@@ -32,23 +32,6 @@ if [ $(hostname) == 'gitlab.gnome.org' ]; then
       git config hooks.mailinglist commits-list gnome org
     fi
   fi
-elif [ $(hostname) == 'git.gnome.org' ]; then
-  if [ $basedir = "${GITLABDIR}/GNOME" ]; then
-    gitlabgroup='GNOME'
-  elif [ $basedir = "${GITLABDIR}/Infrastructure" ]; then
-    gitlabgroup='Infrastructure'
-  fi
-
-    cat <<EOF 1>&2
----
-The ${projectshort} repository has moved to Gitlab. Please update
-your Git remote to:
-
-    git gitlab gnome org:${gitlabgroup}/${projectshort}.git
-
----
-EOF
-    exit 1
 fi
 
 my_uid=`id -u`
diff --git a/run-git-or-special-cmd b/run-git-or-special-cmd
index a01ba45..0c89509 100755
--- a/run-git-or-special-cmd
+++ b/run-git-or-special-cmd
@@ -55,8 +55,8 @@ def validate_git_dir(path, readonly):
         print >>sys.stderr, "git repository does not exist."
         sys.exit(1)
 
-    if not (path.startswith('/git/') or path.startswith('/var/')):
-        print >>sys.stderr, "git repository is not in /git or /var"
+    if not (path.startswith('/git') or path.startswith('/var/opt/gitlab/git-data/repositories')):
+        print >>sys.stderr, "git repository is not in /git or /var/opt/gitlab/git-data/repositories"
         sys.exit(1)
 
     if (not readonly and not is_sysadmin and
@@ -69,13 +69,28 @@ def validate_git_dir(path, readonly):
 def rungitcommand(args):
     read_git_cmds = [ 'git-upload-pack', 'git-upload-archive' ]
     write_git_cmds = [ 'git-receive-pack' ]
+    special_cmds = {}
 
-    special_cmds = {
-    }
-
-    if args[0] in read_git_cmds or args[0] in write_git_cmds:
+    if args[0] in read_git_cmds:
         validate_git_dir(args[1], args[0] in read_git_cmds)
         cmd = ['/usr/bin/git-shell', '-c', os.environ['SSH_ORIGINAL_COMMAND']]
+    elif args[0] in write_git_cmds:
+        validate_git_dir(args[1], args[0] in write_git_cmds)
+        repo_path = find_and_normalize_git_dir(args[1])
+        repo = find_and_normalize_git_dir(args[1]).split('/')[-1].split('.')[0]
+        gl_path = '/var/opt/gitlab/git-data/repositories'
+
+        if repo_path.startswith('%s/GNOME' % gl_path):
+            gitlab_group = 'GNOME'
+        elif repo_path.startswith('%s/Infrastructure' % gl_path):
+            gitlab_group = 'Infrastructure'
+
+        print >> sys.stderr, ''
+        print >> sys.stderr, 'The %s repository has moved to GitLab. Please update your Git remote to:' % 
repo
+        print >> sys.stderr, '    git gitlab gnome org:%s/%s.git' % (gitlab_group, repo)
+        print >> sys.stderr, ''
+        sys.exit(1)
+
     elif args[0] in special_cmds and not is_translations:
         cmd = [special_cmds[args[0]]]
         cmd.extend(args[1:])


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]