[PATCH 02/16] notmuch-git: add --git-dir argument

Subject: [PATCH 02/16] notmuch-git: add --git-dir argument

Date: Sat, 23 Apr 2022 10:38:34 -0300

To: notmuch@notmuchmail.org

Cc:

From: David Bremner


The intent is to change the names of the environment variables before
releasing this code, so avoid relying on environment variables in the
test framework.
---
 notmuch-git.in | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/notmuch-git.in b/notmuch-git.in
index dd30b5be..62889303 100755
--- a/notmuch-git.in
+++ b/notmuch-git.in
@@ -57,11 +57,7 @@ _LOG = _logging.getLogger('nmbug')
 _LOG.setLevel(_logging.WARNING)
 _LOG.addHandler(_logging.StreamHandler())
 
-NMBGIT = _os.path.expanduser(
-    _os.getenv('NMBGIT', _os.path.join('~', '.nmbug')))
-_NMBGIT = _os.path.join(NMBGIT, '.git')
-if _os.path.isdir(_NMBGIT):
-    NMBGIT = _NMBGIT
+NMBGIT = None
 
 TAG_PREFIX = _os.getenv('NMBPREFIX', 'notmuch::')
 _HEX_ESCAPE_REGEX = _re.compile('%[0-9A-F]{2}')
@@ -718,6 +714,9 @@ if __name__ == '__main__':
     parser = argparse.ArgumentParser(
         description=__doc__.strip(),
         formatter_class=argparse.RawDescriptionHelpFormatter)
+    parser.add_argument(
+        '-C', '--git-dir', metavar='REPO',
+        help='Git repository to operate on.')
     parser.add_argument(
         '-v', '--version', action='version',
         version='%(prog)s {}'.format(__version__))
@@ -830,6 +829,15 @@ if __name__ == '__main__':
 
     args = parser.parse_args()
 
+    if args.git_dir:
+        NMBGIT = args.git_dir
+    else:
+        NMBGIT = _os.path.expanduser(
+        _os.getenv('NMBGIT', _os.path.join('~', '.nmbug')))
+        _NMBGIT = _os.path.join(NMBGIT, '.git')
+        if _os.path.isdir(_NMBGIT):
+            NMBGIT = _NMBGIT
+
     if args.log_level:
         level = getattr(_logging, args.log_level.upper())
         _LOG.setLevel(level)
-- 
2.35.2

_______________________________________________
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-leave@notmuchmail.org

Thread: