d88e95a
From b48eb502d330ec7a543805d7f185ea270df75b90 Mon Sep 17 00:00:00 2001
d88e95a
From: Ondrej Nosek <onosek@redhat.com>
d88e95a
Date: Wed, 12 Apr 2023 00:42:04 +0200
d88e95a
Subject: [PATCH 5/6] Config file option to skip the hook script creation
d88e95a
d88e95a
A new option named "skip_hooks" can be added to the config file
d88e95a
(into the main section). It accepts boolean values and when
d88e95a
the option is present and set, it prevents creating the pre-push
d88e95a
hook script during cloning a dist-git repository.
d88e95a
d88e95a
Fixes: https://pagure.io/fedpkg/issue/515
d88e95a
JIRA: RHELCMP-11491
d88e95a
d88e95a
Signed-off-by: Ondrej Nosek <onosek@redhat.com>
d88e95a
---
d88e95a
 pyrpkg/__init__.py | 14 ++++++++++----
d88e95a
 pyrpkg/cli.py      | 13 +++++++++++--
d88e95a
 2 files changed, 21 insertions(+), 6 deletions(-)
d88e95a
d88e95a
diff --git a/pyrpkg/__init__.py b/pyrpkg/__init__.py
d88e95a
index 187796e..7fddff7 100644
d88e95a
--- a/pyrpkg/__init__.py
d88e95a
+++ b/pyrpkg/__init__.py
d88e95a
@@ -1571,7 +1571,7 @@ class Commands(object):
d88e95a
 
d88e95a
     def clone(self, repo, path=None, branch=None, bare_dir=None,
d88e95a
               anon=False, target=None, depth=None, extra_args=None,
d88e95a
-              config_path=None):
d88e95a
+              config_path=None, skip_hooks=None):
d88e95a
         """Clone a repo, optionally check out a specific branch.
d88e95a
 
d88e95a
         :param str repo: the name of the repository to clone.
d88e95a
@@ -1589,6 +1589,7 @@ class Commands(object):
d88e95a
         :param list extra_args: additional arguments that are passed to
d88e95a
             the clone command.
d88e95a
         :param str config_path: path to the global config file
d88e95a
+        :param bool skip_hooks: skip creation pre-push hook script
d88e95a
         """
d88e95a
 
d88e95a
         if not path:
d88e95a
@@ -1644,7 +1645,8 @@ class Commands(object):
d88e95a
 
d88e95a
         if not bare_dir:
d88e95a
             self._add_git_excludes(os.path.join(path, git_dir))
d88e95a
-            self._add_git_pre_push_hook(os.path.join(path, git_dir), config_path)
d88e95a
+            if not skip_hooks:
d88e95a
+                self._add_git_pre_push_hook(os.path.join(path, git_dir), config_path)
d88e95a
 
d88e95a
         return
d88e95a
 
d88e95a
@@ -1660,7 +1662,7 @@ class Commands(object):
d88e95a
         return repo
d88e95a
 
d88e95a
     def clone_with_dirs(self, repo, anon=False, target=None, depth=None,
d88e95a
-                        extra_args=None, config_path=None):
d88e95a
+                        extra_args=None, config_path=None, skip_hooks=None):
d88e95a
         """Clone a repo old style with subdirs for each branch.
d88e95a
 
d88e95a
         :param str repo: name of the repository to clone.
d88e95a
@@ -1673,6 +1675,7 @@ class Commands(object):
d88e95a
         :param list extra_args: additional arguments that are passed to
d88e95a
             the clone command.
d88e95a
         :param str config_path: path to the global config file
d88e95a
+        :param bool skip_hooks: skip creation pre-push hook script
d88e95a
         """
d88e95a
 
d88e95a
         self._push_url = None
d88e95a
@@ -1731,7 +1734,8 @@ class Commands(object):
d88e95a
 
d88e95a
                 # Add excludes
d88e95a
                 self._add_git_excludes(branch_path)
d88e95a
-                self._add_git_pre_push_hook(branch_path, config_path)
d88e95a
+                if not skip_hooks:
d88e95a
+                    self._add_git_pre_push_hook(branch_path, config_path)
d88e95a
             except (git.GitCommandError, OSError) as e:
d88e95a
                 raise rpkgError('Could not locally clone %s from %s: %s'
d88e95a
                                 % (branch, repo_path, e))
d88e95a
@@ -1820,6 +1824,8 @@ class Commands(object):
d88e95a
             # This file was generated by {0} when cloning the repository.
d88e95a
             # You can edit it to your liking or delete completely. It will not
d88e95a
             # be recreated.
d88e95a
+            # Creating this file can be also prevented by adding an option
d88e95a
+            # "skip_hooks = True" into the {0}'s config file; [{0}] section.
d88e95a
 
d88e95a
             _remote="$1"
d88e95a
             _url="$2"
d88e95a
diff --git a/pyrpkg/cli.py b/pyrpkg/cli.py
d88e95a
index 3d8ce33..a1f3f44 100644
d88e95a
--- a/pyrpkg/cli.py
d88e95a
+++ b/pyrpkg/cli.py
d88e95a
@@ -2177,13 +2177,21 @@ class cliClient(object):
d88e95a
             self.log.warning("Repo name should't contain '.git' suffix. "
d88e95a
                              "Correcting the repo name: '%s'" % repo)
d88e95a
 
d88e95a
+        skip_hooks = None
d88e95a
+        if self.config.has_option(self.name, "skip_hooks"):
d88e95a
+            try:
d88e95a
+                skip_hooks = self.config.getboolean(self.name, "skip_hooks")
d88e95a
+            except ValueError:
d88e95a
+                self.log.error("Error: config file option 'skip_hooks'")
d88e95a
+                raise
d88e95a
         if self.args.branches:
d88e95a
             self.cmd.clone_with_dirs(self.args.repo[0],
d88e95a
                                      anon=self.args.anonymous,
d88e95a
                                      target=self.args.clone_target,
d88e95a
                                      depth=self.args.depth,
d88e95a
                                      extra_args=self.extra_args,
d88e95a
-                                     config_path=self.args.config)
d88e95a
+                                     config_path=self.args.config,
d88e95a
+                                     skip_hooks=skip_hooks)
d88e95a
         else:
d88e95a
             self.cmd.clone(self.args.repo[0],
d88e95a
                            branch=self.args.branch,
d88e95a
@@ -2191,7 +2199,8 @@ class cliClient(object):
d88e95a
                            target=self.args.clone_target,
d88e95a
                            depth=self.args.depth,
d88e95a
                            extra_args=self.extra_args,
d88e95a
-                           config_path=self.args.config)
d88e95a
+                           config_path=self.args.config,
d88e95a
+                           skip_hooks=skip_hooks)
d88e95a
 
d88e95a
     def commit(self):
d88e95a
         if self.args.with_changelog and not self.args.message:
d88e95a
-- 
d88e95a
2.39.2
d88e95a