import tempfile
from gbp.command_wrappers import (Command,
CommandExecFailed,
- GitAdd,
GitCommand)
from gbp.config import (GbpOptionParser, GbpOptionGroup)
from gbp.errors import GbpError
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
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
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
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
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:
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
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
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():
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
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"])()