string = p.fromchild.readline().strip()
if p.wait():
raise GitException, '%s failed' % str(cmd)
string = p.fromchild.readline().strip()
if p.wait():
raise GitException, '%s failed' % str(cmd)
-def __tree_status(files = [], tree_id = 'HEAD', unknown = False, noexclude = True):
+def __tree_status(files = [], tree_id = 'HEAD', unknown = False,
+ noexclude = True):
- exclude_file = os.path.join(base_dir, 'exclude')
- base_exclude = [ '--exclude=*.[ao]', '--exclude=.*' '--exclude=TAGS',
- '--exclude=tags', '--exclude=*~', '--exclude=#*',
- '--exclude-per-directory=.gitignore' ]
- extra_exclude = []
+ exclude_file = os.path.join(base_dir, 'info', 'exclude')
+ base_exclude = ['--exclude=%s' % s for s in
+ ['*.[ao]', '*.pyc', '.*', '*~', '#*', 'TAGS', 'tags']]
+ base_exclude.append('--exclude-per-directory=.gitignore')
+
fs = tuple(line.rstrip().split(' ',4)[-1].split('\t',1))
if fs[1] not in conflicts:
cache_files.append(fs)
fs = tuple(line.rstrip().split(' ',4)[-1].split('\t',1))
if fs[1] not in conflicts:
cache_files.append(fs)
- # valid link
- if os.path.islink(head_link) and os.path.isfile(head_link):
- return os.path.basename(os.readlink(head_link))
- else:
- raise GitException, 'Invalid .git/HEAD link. Git tree not initialised?'
+ return os.path.basename(_output_one_line('git-symbolic-ref HEAD'))
- write_string(head_link, val)
+ global __head
+
+ __head = val
+ if __run('git-update-ref HEAD', [val]) != 0:
+ raise GitException, 'Could not update HEAD to "%s".' % val
+
+def rev_parse(git_id):
+ """Parse the string and return a verified SHA1 id
+ """
+ return _output_one_line(['git-rev-parse', '--verify', git_id])
raise GitException, 'Unable to add file'
def rm(files, force = False):
raise GitException, 'Unable to add file'
def rm(files, force = False):
def update_cache(files = [], force = False):
"""Update the cache information for the given files
def update_cache(files = [], force = False):
"""Update the cache information for the given files
rm_files = [x[1] for x in cache_files if x[0] in ['D']]
m_files = [x[1] for x in cache_files if x[0] in ['M']]
rm_files = [x[1] for x in cache_files if x[0] in ['D']]
m_files = [x[1] for x in cache_files if x[0] in ['M']]
- if add_files and __run('git-update-cache --add --', add_files) != 0:
- raise GitException, 'Failed git-update-cache --add'
- if rm_files and __run('git-update-cache --force-remove --', rm_files) != 0:
- raise GitException, 'Failed git-update-cache --rm'
- if m_files and __run('git-update-cache --', m_files) != 0:
- raise GitException, 'Failed git-update-cache'
+ if add_files and __run('git-update-index --add --', add_files) != 0:
+ raise GitException, 'Failed git-update-index --add'
+ if rm_files and __run('git-update-index --force-remove --', rm_files) != 0:
+ raise GitException, 'Failed git-update-index --rm'
+ if m_files and __run('git-update-index --', m_files) != 0:
+ raise GitException, 'Failed git-update-index'
return True
def commit(message, files = [], parents = [], allowempty = False,
return True
def commit(message, files = [], parents = [], allowempty = False,
author_name = None, author_email = None, author_date = None,
committer_name = None, committer_email = None):
"""Commit the current tree to repository
author_name = None, author_email = None, author_date = None,
committer_name = None, committer_email = None):
"""Commit the current tree to repository
+def apply_diff(rev1, rev2):
+ """Apply the diff between rev1 and rev2 onto the current
+ index. This function doesn't need to raise an exception since it
+ is only used for fast-pushing a patch. If this operation fails,
+ the pushing would fall back to the three-way merge.
+ """
+ return os.system('git-diff-tree -p %s %s | git-apply --index 2> /dev/null'
+ % (rev1, rev2)) == 0
+
def merge(base, head1, head2):
"""Perform a 3-way merge between base, head1 and head2 into the
local tree
def merge(base, head1, head2):
"""Perform a 3-way merge between base, head1 and head2 into the
local tree
raise GitException, 'git-read-tree failed (local changes maybe?)'
# this can fail if there are conflicts
raise GitException, 'git-read-tree failed (local changes maybe?)'
# this can fail if there are conflicts
raise GitException, 'git-merge-cache failed (possible conflicts)'
def status(files = [], modified = False, new = False, deleted = False,
raise GitException, 'git-merge-cache failed (possible conflicts)'
def status(files = [], modified = False, new = False, deleted = False,
def diff(files = [], rev1 = 'HEAD', rev2 = None, out_fd = None):
"""Show the diff between rev1 and rev2
"""
def diff(files = [], rev1 = 'HEAD', rev2 = None, out_fd = None):
"""Show the diff between rev1 and rev2
"""
if rev2:
diff_str = _output(['git-diff-tree', '-p', rev1, rev2] + files)
else:
if rev2:
diff_str = _output(['git-diff-tree', '-p', rev1, rev2] + files)
else:
- diff_str = _output(['git-diff-cache', '-p', rev1] + files)
+ os.system('git-update-index --refresh > /dev/null')
+ diff_str = _output(['git-diff-index', '-p', rev1] + files)
p=popen2.Popen3('git-apply --stat')
diff(files, rev1, rev2, p.tochild)
p.tochild.close()
p=popen2.Popen3('git-apply --stat')
diff(files, rev1, rev2, p.tochild)
p.tochild.close()
+def barefiles(rev1, rev2):
+ """Return the files modified between rev1 and rev2, without status info
+ """
+
+ str = ''
+ for line in _output_lines('git-diff-tree -r %s %s' % (rev1, rev2)):
+ str += '%s\n' % line.rstrip().split(' ',4)[-1].split('\t',1)[-1]
+
+ return str.rstrip()
+
def checkout(files = [], tree_id = None, force = False):
"""Check out the given or all files
"""
if tree_id and __run('git-read-tree -m', [tree_id]) != 0:
raise GitException, 'Failed git-read-tree -m %s' % tree_id
def checkout(files = [], tree_id = None, force = False):
"""Check out the given or all files
"""
if tree_id and __run('git-read-tree -m', [tree_id]) != 0:
raise GitException, 'Failed git-read-tree -m %s' % tree_id
-def pull(location, head = None, tag = None):
- """Fetch changes from the remote repository. At the moment, just
- use the 'git fetch' scripts
+def pull(repository = 'origin', refspec = None):
+ """Pull changes from the remote repository. At the moment, just
+ use the 'git pull' command
def apply_patch(filename = None):
"""Apply a patch onto the current index. There must not be any
local changes in the tree, otherwise the command fails
"""
def apply_patch(filename = None):
"""Apply a patch onto the current index. There must not be any
local changes in the tree, otherwise the command fails
"""