summaryrefslogtreecommitdiff
path: root/0018-Config-file-option-to-skip-the-hook-script-creation.patch
blob: fa9aa017bf5a396fbce1290a162d69c050dfb500 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
From b48eb502d330ec7a543805d7f185ea270df75b90 Mon Sep 17 00:00:00 2001
From: Ondrej Nosek <onosek@redhat.com>
Date: Wed, 12 Apr 2023 00:42:04 +0200
Subject: [PATCH 5/6] Config file option to skip the hook script creation

A new option named "skip_hooks" can be added to the config file
(into the main section). It accepts boolean values and when
the option is present and set, it prevents creating the pre-push
hook script during cloning a dist-git repository.

Fixes: https://pagure.io/fedpkg/issue/515
JIRA: RHELCMP-11491

Signed-off-by: Ondrej Nosek <onosek@redhat.com>
---
 pyrpkg/__init__.py | 14 ++++++++++----
 pyrpkg/cli.py      | 13 +++++++++++--
 2 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/pyrpkg/__init__.py b/pyrpkg/__init__.py
index 187796e..7fddff7 100644
--- a/pyrpkg/__init__.py
+++ b/pyrpkg/__init__.py
@@ -1571,7 +1571,7 @@ class Commands(object):
 
     def clone(self, repo, path=None, branch=None, bare_dir=None,
               anon=False, target=None, depth=None, extra_args=None,
-              config_path=None):
+              config_path=None, skip_hooks=None):
         """Clone a repo, optionally check out a specific branch.
 
         :param str repo: the name of the repository to clone.
@@ -1589,6 +1589,7 @@ class Commands(object):
         :param list extra_args: additional arguments that are passed to
             the clone command.
         :param str config_path: path to the global config file
+        :param bool skip_hooks: skip creation pre-push hook script
         """
 
         if not path:
@@ -1644,7 +1645,8 @@ class Commands(object):
 
         if not bare_dir:
             self._add_git_excludes(os.path.join(path, git_dir))
-            self._add_git_pre_push_hook(os.path.join(path, git_dir), config_path)
+            if not skip_hooks:
+                self._add_git_pre_push_hook(os.path.join(path, git_dir), config_path)
 
         return
 
@@ -1660,7 +1662,7 @@ class Commands(object):
         return repo
 
     def clone_with_dirs(self, repo, anon=False, target=None, depth=None,
-                        extra_args=None, config_path=None):
+                        extra_args=None, config_path=None, skip_hooks=None):
         """Clone a repo old style with subdirs for each branch.
 
         :param str repo: name of the repository to clone.
@@ -1673,6 +1675,7 @@ class Commands(object):
         :param list extra_args: additional arguments that are passed to
             the clone command.
         :param str config_path: path to the global config file
+        :param bool skip_hooks: skip creation pre-push hook script
         """
 
         self._push_url = None
@@ -1731,7 +1734,8 @@ class Commands(object):
 
                 # Add excludes
                 self._add_git_excludes(branch_path)
-                self._add_git_pre_push_hook(branch_path, config_path)
+                if not skip_hooks:
+                    self._add_git_pre_push_hook(branch_path, config_path)
             except (git.GitCommandError, OSError) as e:
                 raise rpkgError('Could not locally clone %s from %s: %s'
                                 % (branch, repo_path, e))
@@ -1820,6 +1824,8 @@ class Commands(object):
             # This file was generated by {0} when cloning the repository.
             # You can edit it to your liking or delete completely. It will not
             # be recreated.
+            # Creating this file can be also prevented by adding an option
+            # "skip_hooks = True" into the {0}'s config file; [{0}] section.
 
             _remote="$1"
             _url="$2"
diff --git a/pyrpkg/cli.py b/pyrpkg/cli.py
index 3d8ce33..a1f3f44 100644
--- a/pyrpkg/cli.py
+++ b/pyrpkg/cli.py
@@ -2177,13 +2177,21 @@ class cliClient(object):
             self.log.warning("Repo name should't contain '.git' suffix. "
                              "Correcting the repo name: '%s'" % repo)
 
+        skip_hooks = None
+        if self.config.has_option(self.name, "skip_hooks"):
+            try:
+                skip_hooks = self.config.getboolean(self.name, "skip_hooks")
+            except ValueError:
+                self.log.error("Error: config file option 'skip_hooks'")
+                raise
         if self.args.branches:
             self.cmd.clone_with_dirs(self.args.repo[0],
                                      anon=self.args.anonymous,
                                      target=self.args.clone_target,
                                      depth=self.args.depth,
                                      extra_args=self.extra_args,
-                                     config_path=self.args.config)
+                                     config_path=self.args.config,
+                                     skip_hooks=skip_hooks)
         else:
             self.cmd.clone(self.args.repo[0],
                            branch=self.args.branch,
@@ -2191,7 +2199,8 @@ class cliClient(object):
                            target=self.args.clone_target,
                            depth=self.args.depth,
                            extra_args=self.extra_args,
-                           config_path=self.args.config)
+                           config_path=self.args.config,
+                           skip_hooks=skip_hooks)
 
     def commit(self):
         if self.args.with_changelog and not self.args.message:
-- 
2.39.2