summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAndrej Shadura <andrew.shadura@collabora.co.uk>2021-02-07 20:06:40 +0100
committerGuido Günther <agx@sigxcpu.org>2021-03-11 12:48:47 +0100
commit7a9079aacda151005063e673c6e84c4179170ab2 (patch)
tree0016579385cf4eef8c41626030986c986bf9e773
parent20052e18db3ee87b62fe9acb537564ac87e4d7f2 (diff)
scripts: Add setup-gitattributes subcommand
The setup-gitattributes subcommands overrides Git attributes unconditionally, without verifying first the package ships any .gitattributes files. Signed-off-by: Andrej Shadura <andrew.shadura@collabora.co.uk>
-rw-r--r--gbp/scripts/setup_gitattributes.py90
1 files changed, 90 insertions, 0 deletions
diff --git a/gbp/scripts/setup_gitattributes.py b/gbp/scripts/setup_gitattributes.py
new file mode 100644
index 00000000..23eaf360
--- /dev/null
+++ b/gbp/scripts/setup_gitattributes.py
@@ -0,0 +1,90 @@
+# vim: set fileencoding=utf-8 :
+#
+# (C) 2021 Andrej Shadura <andrew@shadura.me>
+# (C) 2021 Collabora Limited
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, please see
+# <http://www.gnu.org/licenses/>
+#
+"""Setup Git attributes to incapacitate .gitattributes shipped by the upstream"""
+
+import os
+import sys
+import gbp.log
+from gbp.command_wrappers import CommandExecFailed
+from gbp.config import GbpOptionParserDebian
+from gbp.deb.git import GitRepositoryError, DebianGitRepository
+from gbp.errors import GbpError
+from gbp.scripts.common import ExitCodes
+from gbp.scripts.common.repo_setup import setup_gitattributes
+
+
+def build_parser(name):
+ try:
+ parser = GbpOptionParserDebian(command=os.path.basename(name), prefix='',
+ usage='%prog - disable harmful Git attributes')
+ except GbpError as err:
+ gbp.log.err(err)
+ return None
+
+ parser.add_option("--verbose", action="store_true", dest="verbose",
+ default=False, help="verbose command execution")
+ parser.add_config_file_option(option_name="color", dest="color",
+ type='tristate')
+ parser.add_config_file_option(option_name="color-scheme",
+ dest="color_scheme")
+
+ return parser
+
+
+def parse_args(argv):
+ """Parse the command line arguments
+ @return: options and arguments
+ """
+
+ parser = build_parser(argv[0])
+ if not parser:
+ return None, None
+
+ (options, args) = parser.parse_args(argv[1:])
+ gbp.log.setup(options.color, options.verbose, options.color_scheme)
+ return options, args
+
+
+def main(argv):
+ repo = None
+
+ (options, args) = parse_args(argv)
+ if not options:
+ return ExitCodes.parse_error
+
+ try:
+ try:
+ repo = DebianGitRepository('.')
+ except GitRepositoryError:
+ raise GbpError("%s is not a git repository" % (os.path.abspath('.')))
+
+ setup_gitattributes(repo)
+ except (GitRepositoryError, GbpError, CommandExecFailed) as err:
+ if str(err):
+ gbp.log.err(err)
+ except KeyboardInterrupt:
+ gbp.log.err("Interrupted. Aborting.")
+
+ return 0
+
+
+if __name__ == "__main__":
+ sys.exit(main(sys.argv))
+
+# vim:et:ts=4:sw=4:et:sts=4:ai:set list listchars=tab\:»·,trail\:·: