--- /dev/null
+"""Access to the GIT base directory
+"""
+
+__copyright__ = """
+Copyright (C) 2006, Catalin Marinas <catalin.marinas@gmail.com>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License version 2 as
+published by the Free Software Foundation.
+
+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, write to the Free Software
+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+"""
+
+import os
+
+class BaseDirException(Exception):
+ pass
+
+def __output(cmd):
+ f = os.popen(cmd, 'r')
+ string = f.readline().rstrip()
+ if f.close():
+ raise BaseDirException, 'Error: failed to execute "%s"' % cmd
+ return string
+
+# GIT_DIR value cached
+__base_dir = None
+
+def get():
+ """Return the .git directory location
+ """
+ global __base_dir
+
+ if not __base_dir:
+ if 'GIT_DIR' in os.environ:
+ __base_dir = os.environ['GIT_DIR']
+ else:
+ __base_dir = __output('git-rev-parse --git-dir')
+
+ return __base_dir
from stgit.commands.common import *
from stgit.utils import *
-from stgit import stack, git
+from stgit import stack, git, basedir
help = 'manage development branches'
if len(args) != 0:
parser.error('incorrect number of arguments')
- branches = os.listdir(os.path.join(git.get_base_dir(), 'refs', 'heads'))
+ branches = os.listdir(os.path.join(basedir.get(), 'refs', 'heads'))
branches.sort()
max_len = max([len(i) for i in branches])
from optparse import OptionParser, make_option
from stgit.utils import *
-from stgit import stack, git
+from stgit import stack, git, basedir
crt_series = None
' are doing, use the "refresh -f" command'
def check_conflicts():
- if os.path.exists(os.path.join(git.get_base_dir(), 'conflicts')):
+ if os.path.exists(os.path.join(basedir.get(), 'conflicts')):
raise CmdException, 'Unsolved conflicts. Please resolve them first'
def print_crt_patch(branch = None):
if conflicts:
for filename in conflicts:
resolved(filename, reset)
- os.remove(os.path.join(git.get_base_dir(), 'conflicts'))
+ os.remove(os.path.join(basedir.get(), 'conflicts'))
def push_patches(patches, check_merged = False):
"""Push multiple patches onto the stack. This function is shared
from stgit.commands.common import *
from stgit.utils import *
-from stgit import stack, git
+from stgit import stack, git, basedir
help = 'exports a series of patches to <dir> (or patches)'
else:
patch_tmpl_list = []
- patch_tmpl_list += [os.path.join(git.get_base_dir(), 'patchexport.tmpl'),
+ patch_tmpl_list += [os.path.join(basedir.get(), 'patchexport.tmpl'),
os.path.join(sys.prefix,
'share/stgit/templates/patchexport.tmpl')]
tmpl = ''
from stgit.commands.common import *
from stgit.utils import *
-from stgit import stack, git
+from stgit import stack, git, basedir
from stgit.config import config
if options.cover:
tfile_list = [options.cover]
else:
- tfile_list = [os.path.join(git.get_base_dir(), 'covermail.tmpl'),
+ tfile_list = [os.path.join(basedir.get(), 'covermail.tmpl'),
os.path.join(sys.prefix,
'share/stgit/templates/covermail.tmpl')]
if options.template:
tfile_list = [options.template]
else:
- tfile_list = [os.path.join(git.get_base_dir(), 'patchmail.tmpl'),
+ tfile_list = [os.path.join(basedir.get(), 'patchmail.tmpl'),
os.path.join(sys.prefix,
'share/stgit/templates/patchmail.tmpl')]
tmpl = None
from stgit.commands.common import *
from stgit.utils import *
-from stgit import stack, git
+from stgit import stack, git, basedir
help = 'mark a file conflict as solved'
# save or remove the conflicts file
if conflicts == []:
- os.remove(os.path.join(git.get_base_dir(), 'conflicts'))
+ os.remove(os.path.join(basedir.get(), 'conflicts'))
else:
- f = file(os.path.join(git.get_base_dir(), 'conflicts'), 'w+')
+ f = file(os.path.join(basedir.get(), 'conflicts'), 'w+')
f.writelines([line + '\n' for line in conflicts])
f.close()
import os, ConfigParser
+from stgit import basedir
-if 'GIT_DIR' in os.environ:
- __git_dir = os.environ['GIT_DIR']
-else:
- __git_dir = '.git'
config = ConfigParser.RawConfigParser()
# Read the configuration files (if any) and override the default settings
config.read('/etc/stgitrc')
config.read(os.path.expanduser('~/.stgitrc'))
-config.read(os.path.join(__git_dir, 'stgitrc'))
+config.read(os.path.join(basedir.get(), 'stgitrc'))
# [gitmergeonefile] section is deprecated. In case it exists copy the
# options/values to the [stgit] one
import sys, os, popen2, re, gitmergeonefile
+from stgit import basedir
from stgit.utils import *
# git exception class
# Functions
#
-# GIT_DIR value cached
-__base_dir = None
-
-def get_base_dir():
- """Different start-up variables read from the environment
- """
- global __base_dir
-
- if not __base_dir:
- if 'GIT_DIR' in os.environ:
- __base_dir = os.environ['GIT_DIR']
- else:
- __base_dir = _output_one_line('git-rev-parse --git-dir')
-
- return __base_dir
-
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
"""
- conflicts_file = os.path.join(get_base_dir(), 'conflicts')
+ conflicts_file = os.path.join(basedir.get(), 'conflicts')
if os.path.isfile(conflicts_file):
f = file(conflicts_file)
names = [line.strip() for line in f.readlines()]
# unknown files
if unknown:
- exclude_file = os.path.join(get_base_dir(), 'info', 'exclude')
+ exclude_file = os.path.join(basedir.get(), 'info', 'exclude')
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 os.path.isfile(os.path.join(get_base_dir(), 'MERGE_HEAD')):
- os.remove(os.path.join(get_base_dir(), 'MERGE_HEAD'))
+ if os.path.isfile(os.path.join(basedir.get(), 'MERGE_HEAD')):
+ os.remove(os.path.join(basedir.get(), 'MERGE_HEAD'))
def switch_branch(name):
"""Switch to a git branch
__head = tree_id
set_head_file(new_head)
- if os.path.isfile(os.path.join(get_base_dir(), 'MERGE_HEAD')):
- os.remove(os.path.join(get_base_dir(), 'MERGE_HEAD'))
+ if os.path.isfile(os.path.join(basedir.get(), 'MERGE_HEAD')):
+ os.remove(os.path.join(basedir.get(), 'MERGE_HEAD'))
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
- os.remove(os.path.join(get_base_dir(), branch_head))
+ os.remove(os.path.join(basedir.get(), branch_head))
def rename_branch(from_name, to_name):
"""Rename a git branch
if get_head_file() == from_name:
set_head_file(to_head)
- os.rename(os.path.join(get_base_dir(), from_head), \
- os.path.join(get_base_dir(), to_head))
+ os.rename(os.path.join(basedir.get(), from_head), \
+ os.path.join(basedir.get(), to_head))
def add(names):
"""Add the files or recursively add the directory contents
"""
import sys, os
+from stgit import basedir
from stgit.config import config
from stgit.utils import append_string
os.remove(src2)
pass
-# GIT_DIR value cached
-__base_dir = None
-
def __conflict(path):
"""Write the conflict file for the 'path' variable and exit
"""
- global __base_dir
-
- if not __base_dir:
- if 'GIT_DIR' in os.environ:
- __base_dir = os.environ['GIT_DIR']
- else:
- __base_dir = __output('git-rev-parse --git-dir')
-
- append_string(os.path.join(__base_dir, 'conflicts'), path)
+ append_string(os.path.join(basedir.get(), 'conflicts'), path)
#
import sys, os
from stgit.utils import *
-from stgit import git
+from stgit import git, basedir
from stgit.config import config
def edit_file(series, line, comment, show_patch = True):
fname = '.stgit.msg'
- tmpl = os.path.join(git.get_base_dir(), 'patchdescr.tmpl')
+ tmpl = os.path.join(basedir.get(), 'patchdescr.tmpl')
f = file(fname, 'w+')
if line:
self.__name = name
else:
self.__name = git.get_head_file()
- self.__base_dir = git.get_base_dir()
+ self.__base_dir = basedir.get()
except git.GitException, ex:
raise StackException, 'GIT tree not initialised: %s' % ex