save_patches(): fall back to diffing ignoring submodules in case the user has an old version of git
@@ -164,15 +164,29 @@ class Api(object):
"""
root = self.git.root
if self.git.dirty:
- with open(os.path.join(out_dir, 'diff.patch'), 'wb') as patch:
+ patch_path = os.path.join(out_dir, 'diff.patch')
+ try:
+ with open(patch_path, 'wb') as patch:
# we diff against HEAD to ensure we get changes in the index
subprocess.check_call(['git', 'diff', '--submodule=diff', 'HEAD'], stdout=patch, cwd=root)
+ except subprocess.CalledProcessError:
+ # the --submodule=diff option doesn't exist in pre-2.11 versions of git (november 2016)
+ # https://stackoverflow.com/questions/10757091/git-list-of-all-changed-files-including-those-in-submodules
+ print("WARNING: Diffing ignoring submodules because git is an old version (< 2.11)")
+ with open(patch_path, 'wb') as patch:
+ subprocess.check_call(['git', 'diff', 'HEAD'], stdout=patch, cwd=root)
upstream_commit = self.git.get_upstream_fork_point()
if upstream_commit and upstream_commit != self.git.repo.head.commit:
sha = upstream_commit.hexsha
- with open(os.path.join(out_dir, 'upstream_diff_{}.patch'.format(sha)), 'wb') as upstream_patch:
+ upstream_patch_path = os.path.join(out_dir, 'upstream_diff_{}.patch'.format(sha))
+ try:
+ with open(upstream_patch_path, 'wb') as upstream_patch:
subprocess.check_call(['git', 'diff', '--submodule=diff', sha], stdout=upstream_patch, cwd=root)
+ except subprocess.CalledProcessError:
+ print("WARNING: Diffing ignoring submodules because git is an old version (< 2.11)")
+ with open(upstream_patch_path, 'wb') as upstream_patch:
+ subprocess.check_call(['git', 'diff', sha], stdout=upstream_patch, cwd=root)
def set_current_run_id(self, run_id):
self._current_run_id = run_id
