chiark / gitweb /
Use git-rev-parse to find the local GIT repository
authorChuck Lever <cel@netapp.com>
Tue, 29 Nov 2005 22:09:40 +0000 (17:09 -0500)
committerCatalin Marinas <catalin.marinas@gmail.com>
Wed, 30 Nov 2005 22:11:14 +0000 (22:11 +0000)
Use the latest git-rev-parse technology to allow some StGIT commands to
function correctly in subdirectories of the working directory.

Any command that relies on git-read-tree still doesn't work (changes to
GIT forthcoming).

Signed-off-by: Chuck Lever <cel@netapp.com>
stgit/commands/branch.py
stgit/commands/common.py
stgit/commands/export.py
stgit/commands/mail.py
stgit/commands/resolved.py
stgit/git.py
stgit/stack.py

index 63b3797d3f71a286f1280eac6a7417457dc0d10d..ccf1f6baefafb0585a0ebfe0f1f8822b249f0dd6 100644 (file)
@@ -136,7 +136,7 @@ def func(parser, options, args):
         if len(args) != 0:
             parser.error('incorrect number of arguments')
 
         if len(args) != 0:
             parser.error('incorrect number of arguments')
 
-        branches = os.listdir(os.path.join(git.base_dir, 'refs', 'heads'))
+        branches = os.listdir(os.path.join(git.get_base_dir(), 'refs', 'heads'))
         branches.sort()
         max_len = max([len(i) for i in branches])
 
         branches.sort()
         max_len = max([len(i) for i in branches])
 
index e437111eb60f237a052a1a4f077a26dfe9cdc218..8084cbd2f7963e2965ac322c95a2c9c34fc84adc 100644 (file)
@@ -96,7 +96,7 @@ def check_head_top_equal():
               '  are doing, use the "refresh -f" command'
 
 def check_conflicts():
               '  are doing, use the "refresh -f" command'
 
 def check_conflicts():
-    if os.path.exists(os.path.join(git.base_dir, 'conflicts')):
+    if os.path.exists(os.path.join(git.get_base_dir(), 'conflicts')):
         raise CmdException, 'Unsolved conflicts. Please resolve them first'
 
 def print_crt_patch(branch = None):
         raise CmdException, 'Unsolved conflicts. Please resolve them first'
 
 def print_crt_patch(branch = None):
@@ -130,7 +130,7 @@ def resolved_all(reset = None):
     if conflicts:
         for filename in conflicts:
             resolved(filename, reset)
     if conflicts:
         for filename in conflicts:
             resolved(filename, reset)
-        os.remove(os.path.join(git.base_dir, 'conflicts'))
+        os.remove(os.path.join(git.get_base_dir(), 'conflicts'))
 
 def name_email(address):
     """Return a tuple consisting of the name and email parsed from a
 
 def name_email(address):
     """Return a tuple consisting of the name and email parsed from a
index 0ef7d070914aac3937d298a39677e4e730822f99..b33c9eab270c2208ad78e27bed685f30678109b8 100644 (file)
@@ -132,7 +132,7 @@ def func(parser, options, args):
     else:
         patch_tmpl_list = []
 
     else:
         patch_tmpl_list = []
 
-    patch_tmpl_list += [os.path.join(git.base_dir, 'patchexport.tmpl'),
+    patch_tmpl_list += [os.path.join(git.get_base_dir(), 'patchexport.tmpl'),
                         os.path.join(sys.prefix,
                                      'share/stgit/templates/patchexport.tmpl')]
     tmpl = ''
                         os.path.join(sys.prefix,
                                      'share/stgit/templates/patchexport.tmpl')]
     tmpl = ''
index 7cc18bc199b7cd8909327d673dcb1b8a37537724..b3b7b494f0115510c20d3b9f554a3ea2a689e221 100644 (file)
@@ -419,7 +419,7 @@ def func(parser, options, args):
         if options.cover:
             tfile_list = [options.cover]
         else:
         if options.cover:
             tfile_list = [options.cover]
         else:
-            tfile_list = [os.path.join(git.base_dir, 'covermail.tmpl'),
+            tfile_list = [os.path.join(git.get_base_dir(), 'covermail.tmpl'),
                           os.path.join(sys.prefix,
                                        'share/stgit/templates/covermail.tmpl')]
 
                           os.path.join(sys.prefix,
                                        'share/stgit/templates/covermail.tmpl')]
 
@@ -450,7 +450,7 @@ def func(parser, options, args):
     if options.template:
         tfile_list = [options.template]
     else:
     if options.template:
         tfile_list = [options.template]
     else:
-        tfile_list = [os.path.join(git.base_dir, 'patchmail.tmpl'),
+        tfile_list = [os.path.join(git.get_base_dir(), 'patchmail.tmpl'),
                       os.path.join(sys.prefix,
                                    'share/stgit/templates/patchmail.tmpl')]
     tmpl = None
                       os.path.join(sys.prefix,
                                    'share/stgit/templates/patchmail.tmpl')]
     tmpl = None
index d21ecc9afe3ef8f6c2c38c25220ea4f26e7e887c..585c51bf3584079f8c9b91f05d61bd5de90c6f46 100644 (file)
@@ -65,8 +65,8 @@ def func(parser, options, args):
 
     # save or remove the conflicts file
     if conflicts == []:
 
     # save or remove the conflicts file
     if conflicts == []:
-        os.remove(os.path.join(git.base_dir, 'conflicts'))
+        os.remove(os.path.join(git.get_base_dir(), 'conflicts'))
     else:
     else:
-        f = file(os.path.join(git.base_dir, 'conflicts'), 'w+')
+        f = file(os.path.join(git.get_base_dir(), 'conflicts'), 'w+')
         f.writelines([line + '\n' for line in conflicts])
         f.close()
         f.writelines([line + '\n' for line in conflicts])
         f.close()
index b19f75fc54d3afaee5d97c71eaca459513c950ac..2cedeaa4d04007069468c518e6c830053f311397 100644 (file)
@@ -27,12 +27,6 @@ class GitException(Exception):
     pass
 
 
     pass
 
 
-# Different start-up variables read from the environment
-if 'GIT_DIR' in os.environ:
-    base_dir = os.environ['GIT_DIR']
-else:
-    base_dir = '.git'
-
 
 #
 # Classes
 
 #
 # Classes
@@ -87,6 +81,15 @@ __commits = dict()
 #
 # Functions
 #
 #
 # Functions
 #
+
+def get_base_dir():
+    """Different start-up variables read from the environment
+    """
+    if 'GIT_DIR' in os.environ:
+        return os.environ['GIT_DIR']
+    else:
+        return _output_one_line('git-rev-parse --git-dir')
+
 def get_commit(id_hash):
     """Commit objects factory. Save/look-up them in the __commits
     dictionary
 def get_commit(id_hash):
     """Commit objects factory. Save/look-up them in the __commits
     dictionary
@@ -103,7 +106,7 @@ def get_commit(id_hash):
 def get_conflicts():
     """Return the list of file conflicts
     """
 def get_conflicts():
     """Return the list of file conflicts
     """
-    conflicts_file = os.path.join(base_dir, 'conflicts')
+    conflicts_file = os.path.join(get_base_dir(), 'conflicts')
     if os.path.isfile(conflicts_file):
         f = file(conflicts_file)
         names = [line.strip() for line in f.readlines()]
     if os.path.isfile(conflicts_file):
         f = file(conflicts_file)
         names = [line.strip() for line in f.readlines()]
@@ -167,9 +170,6 @@ def __run(cmd, args=None):
         return r
     return 0
 
         return r
     return 0
 
-def __check_base_dir():
-    return os.path.isdir(base_dir)
-
 def __tree_status(files = None, tree_id = 'HEAD', unknown = False,
                   noexclude = True):
     """Returns a list of pairs - [status, filename]
 def __tree_status(files = None, tree_id = 'HEAD', unknown = False,
                   noexclude = True):
     """Returns a list of pairs - [status, filename]
@@ -182,7 +182,7 @@ def __tree_status(files = None, tree_id = 'HEAD', unknown = False,
 
     # unknown files
     if unknown:
 
     # unknown files
     if unknown:
-        exclude_file = os.path.join(base_dir, 'info', 'exclude')
+        exclude_file = os.path.join(get_base_dir(), 'info', 'exclude')
         base_exclude = ['--exclude=%s' % s for s in
                         ['*.[ao]', '*.pyc', '.*', '*~', '#*', 'TAGS', 'tags']]
         base_exclude.append('--exclude-per-directory=.gitignore')
         base_exclude = ['--exclude=%s' % s for s in
                         ['*.[ao]', '*.pyc', '.*', '*~', '#*', 'TAGS', 'tags']]
         base_exclude.append('--exclude-per-directory=.gitignore')
@@ -296,8 +296,8 @@ def create_branch(new_branch, tree_id = None):
     if tree_id:
         switch(tree_id)
 
     if tree_id:
         switch(tree_id)
 
-    if os.path.isfile(os.path.join(base_dir, 'MERGE_HEAD')):
-        os.remove(os.path.join(base_dir, 'MERGE_HEAD'))
+    if os.path.isfile(os.path.join(get_base_dir(), 'MERGE_HEAD')):
+        os.remove(os.path.join(get_base_dir(), 'MERGE_HEAD'))
 
 def switch_branch(name):
     """Switch to a git branch
 
 def switch_branch(name):
     """Switch to a git branch
@@ -316,8 +316,8 @@ def switch_branch(name):
         __head = tree_id
     set_head_file(new_head)
 
         __head = tree_id
     set_head_file(new_head)
 
-    if os.path.isfile(os.path.join(base_dir, 'MERGE_HEAD')):
-        os.remove(os.path.join(base_dir, 'MERGE_HEAD'))
+    if os.path.isfile(os.path.join(get_base_dir(), 'MERGE_HEAD')):
+        os.remove(os.path.join(get_base_dir(), 'MERGE_HEAD'))
 
 def delete_branch(name):
     """Delete a git branch
 
 def delete_branch(name):
     """Delete a git branch
@@ -325,7 +325,7 @@ def delete_branch(name):
     branch_head = os.path.join('refs', 'heads', name)
     if not branch_exists(branch_head):
         raise GitException, 'Branch "%s" does not exist' % name
     branch_head = os.path.join('refs', 'heads', name)
     if not branch_exists(branch_head):
         raise GitException, 'Branch "%s" does not exist' % name
-    os.remove(os.path.join(base_dir, branch_head))
+    os.remove(os.path.join(get_base_dir(), branch_head))
 
 def rename_branch(from_name, to_name):
     """Rename a git branch
 
 def rename_branch(from_name, to_name):
     """Rename a git branch
@@ -339,7 +339,8 @@ def rename_branch(from_name, to_name):
 
     if get_head_file() == from_name:
         set_head_file(to_head)
 
     if get_head_file() == from_name:
         set_head_file(to_head)
-    os.rename(os.path.join(base_dir, from_head), os.path.join(base_dir, to_head))
+    os.rename(os.path.join(get_base_dir(), from_head), \
+              os.path.join(get_base_dir(), to_head))
 
 def add(names):
     """Add the files or recursively add the directory contents
 
 def add(names):
     """Add the files or recursively add the directory contents
index 18b4c6e730c8a5082d7da586f2205adae9c34c9c..dc7c19f80136154ec3014479d1add66ced60ab1c 100644 (file)
@@ -66,7 +66,7 @@ def __clean_comments(f):
 
 def edit_file(series, line, comment, show_patch = True):
     fname = '.stgit.msg'
 
 def edit_file(series, line, comment, show_patch = True):
     fname = '.stgit.msg'
-    tmpl = os.path.join(git.base_dir, 'patchdescr.tmpl')
+    tmpl = os.path.join(git.get_base_dir(), 'patchdescr.tmpl')
 
     f = file(fname, 'w+')
     if line:
 
     f = file(fname, 'w+')
     if line:
@@ -263,9 +263,10 @@ class Series:
             self.__name = git.get_head_file()
 
         if self.__name:
             self.__name = git.get_head_file()
 
         if self.__name:
-            self.__patch_dir = os.path.join(git.base_dir, 'patches',
+            base_dir = git.get_base_dir()
+            self.__patch_dir = os.path.join(base_dir, 'patches',
                                             self.__name)
                                             self.__name)
-            self.__base_file = os.path.join(git.base_dir, 'refs', 'bases',
+            self.__base_file = os.path.join(base_dir, 'refs', 'bases',
                                             self.__name)
             self.__applied_file = os.path.join(self.__patch_dir, 'applied')
             self.__unapplied_file = os.path.join(self.__patch_dir, 'unapplied')
                                             self.__name)
             self.__applied_file = os.path.join(self.__patch_dir, 'applied')
             self.__unapplied_file = os.path.join(self.__patch_dir, 'unapplied')
@@ -386,7 +387,7 @@ class Series:
     def init(self):
         """Initialises the stgit series
         """
     def init(self):
         """Initialises the stgit series
         """
-        bases_dir = os.path.join(git.base_dir, 'refs', 'bases')
+        bases_dir = os.path.join(git.get_base_dir(), 'refs', 'bases')
 
         if self.is_initialised():
             raise StackException, self.__patch_dir + ' already exists'
 
         if self.is_initialised():
             raise StackException, self.__patch_dir + ' already exists'