summaryrefslogtreecommitdiff
path: root/gbp
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2011-10-21 21:20:24 +0200
committerGuido Günther <agx@sigxcpu.org>2011-10-22 15:33:40 +0200
commite7a35319ba55b6cf0b88bc6299a85281de2374c1 (patch)
tree781e9fbcf7dd9b4aaf9014ace0d7adf6050b7f2a /gbp
parent6da5985f2eb0f39d97afb271569de102ff472858 (diff)
Replace GitAdd by GitRepository.add_files
Git-Dch: Ignore
Diffstat (limited to 'gbp')
-rw-r--r--gbp/command_wrappers.py8
-rw-r--r--gbp/git.py46
2 files changed, 38 insertions, 16 deletions
diff --git a/gbp/command_wrappers.py b/gbp/command_wrappers.py
index 3488575..f182e98 100644
--- a/gbp/command_wrappers.py
+++ b/gbp/command_wrappers.py
@@ -293,14 +293,6 @@ class GitTag(GitCommand):
GitCommand.__call__(self, cmd)
-# FIXME: move to gbp.git.add
-class GitAdd(GitCommand):
- """Wrap git add to add new files"""
- def __init__(self, extra_env=None):
- GitCommand.__init__(self, 'add', extra_env=extra_env)
- self.run_error = "Couldn't add files"
-
-
def copy_from(orig_dir, filters=[]):
"""
copy a source tree over via tar
diff --git a/gbp/git.py b/gbp/git.py
index f6e12ae..ebc0297 100644
--- a/gbp/git.py
+++ b/gbp/git.py
@@ -19,7 +19,7 @@
import re
import subprocess
import os.path
-from command_wrappers import (GitCommand, GitAdd, GitBranch, copy_from)
+from command_wrappers import (GitCommand, GitBranch, copy_from)
from errors import GbpError
import log
import dateutil.parser
@@ -372,10 +372,14 @@ class GitRepository(object):
raise GitRepositoryError, "revision '%s' not found" % name
return sha[0].strip()
- def write_tree(self, index=None):
- """write out the current index, return the SHA1"""
- if index:
- extra_env = {'GIT_INDEX_FILE': index }
+ def write_tree(self, index_file=None):
+ """
+ Write out the current index, return the SHA1
+
+ @param index: alternate index file to write the current index to
+ """
+ if index_file:
+ extra_env = {'GIT_INDEX_FILE': index_file }
else:
extra_env = None
@@ -434,9 +438,8 @@ class GitRepository(object):
os.unlink(git_index_file)
except OSError:
pass
- extra_env = { 'GIT_INDEX_FILE': git_index_file,
- 'GIT_WORK_TREE': unpack_dir}
- GitAdd(extra_env=extra_env)(['-f', '.'])
+ self.add_files('.', force=True, index_file=git_index_file,
+ work_tree=unpack_dir)
tree = self.write_tree(git_index_file)
if branch:
@@ -500,6 +503,33 @@ class GitRepository(object):
else:
return False
+
+ def add_files(self, paths, force=False, index_file=None, work_tree=None):
+ """
+ Add files to a git repository
+
+ @param paths: list of files to add
+ @param paths: list or string
+ @param force: add files even if they would be ignores by .gitignore
+ @param force: bool
+ @param index_file: alternative index file to use
+ @param work_tree: alternative working tree to use
+ """
+ extra_env = {}
+
+ if type(paths) in [type(''), type(u'')]:
+ paths = [ paths ]
+
+ args = [ '-f' ] if force else []
+
+ if index_file:
+ extra_env['GIT_INDEX_FILE'] = index_file
+
+ if work_tree:
+ extra_env['GIT_WORK_TREE'] = work_tree
+
+ self._git_command("add", args + paths, extra_env)
+
def format_patches(self, start, end, output_dir):
"""
Output the commits between start and end as patches in output_dir