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>
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])
' 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):
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
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 = ''
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')]
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
# 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'))
- 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()
-# Different start-up variables read from the environment
-if 'GIT_DIR' in os.environ:
- base_dir = os.environ['GIT_DIR']
-else:
- base_dir = '.git'
-
+
+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
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()]
-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]
# 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')
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
__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
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
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
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:
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.__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')
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'