aboutsummaryrefslogtreecommitdiffhomepage
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
parent6da5985f2eb0f39d97afb271569de102ff472858 (diff)
Replace GitAdd by GitRepository.add_files
Git-Dch: Ignore
-rwxr-xr-xexamples/gbp-add-patch3
-rw-r--r--gbp/command_wrappers.py8
-rw-r--r--gbp/git.py46
-rwxr-xr-xgit-buildpackage9
-rw-r--r--tests/03_test_gbp_branch.py2
-rw-r--r--tests/04_test_gbp_submodules.py2
6 files changed, 44 insertions, 26 deletions
diff --git a/examples/gbp-add-patch b/examples/gbp-add-patch
index 357e31cf..8a10eb5d 100755
--- a/examples/gbp-add-patch
+++ b/examples/gbp-add-patch
@@ -40,7 +40,6 @@ import subprocess
import tempfile
from gbp.command_wrappers import (Command,
CommandExecFailed,
- GitAdd,
GitCommand)
from gbp.config import (GbpOptionParser, GbpOptionGroup)
from gbp.errors import GbpError
@@ -144,7 +143,7 @@ def main(argv):
patch = PatchInfo(patchfile)
- GitAdd()([patchfile])
+ repo.add_files(patchfile)
msg = build_commit_msg(repo, patch, options)
GitCommit()(edit=options.edit, msg=msg)
# FIXME: handle the series file
diff --git a/gbp/command_wrappers.py b/gbp/command_wrappers.py
index 34885750..f182e986 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 f6e12ae5..ebc0297c 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
diff --git a/git-buildpackage b/git-buildpackage
index d18fa93d..7b5dca3d 100755
--- a/git-buildpackage
+++ b/git-buildpackage
@@ -30,7 +30,7 @@ import gbp.deb as du
from gbp.git import (GitRepositoryError, GitRepository, build_tag)
from gbp.command_wrappers import (GitTag, Command,
RunAtCommand, CommandExecFailed, PristineTar,
- RemoveTree, GitAdd, CatenateTarArchive)
+ RemoveTree, CatenateTarArchive)
from gbp.config import (GbpOptionParser, GbpOptionGroup)
from gbp.errors import GbpError
from glob import glob
@@ -229,11 +229,8 @@ def git_archive_build_orig(repo, cp, output_dir, options):
def write_wc(repo):
"""write out the current working copy as a treeish object"""
- tree = None
- os.putenv("GIT_INDEX_FILE", wc_index)
- GitAdd()(['-f', '.'])
- tree = repo.write_tree()
- os.unsetenv("GIT_INDEX_FILE")
+ repo.add_files(repo.path, force=True, index_file=wc_index)
+ tree = repo.write_tree(index_file=wc_index)
return tree
def drop_index():
diff --git a/tests/03_test_gbp_branch.py b/tests/03_test_gbp_branch.py
index a3056975..a99391d0 100644
--- a/tests/03_test_gbp_branch.py
+++ b/tests/03_test_gbp_branch.py
@@ -39,7 +39,7 @@ def test_is_empty():
def test_add_files():
"""Add some dummy data"""
shutil.copy(".git/HEAD", "testfile")
- gbp.command_wrappers.GitAdd()(['-f', '.'])
+ repo.add_files('.', force=True)
gbp.command_wrappers.GitCommand("commit", ["-mfoo", "-a"])()
assert True
diff --git a/tests/04_test_gbp_submodules.py b/tests/04_test_gbp_submodules.py
index af44c07a..a6b66bb6 100644
--- a/tests/04_test_gbp_submodules.py
+++ b/tests/04_test_gbp_submodules.py
@@ -55,7 +55,7 @@ def test_empty_has_submodules():
def _add_dummy_data(msg):
shutil.copy(".git/HEAD", testfile_name)
- gbp.command_wrappers.GitAdd()(['-f', '.'])
+ repo.add_files('.', force=True)
gbp.command_wrappers.GitCommand("commit", ["-m%s" % msg, "-a"])()