in sync/landing.py [0:0]
def copy_pr(self, git_work_gecko, git_work_wpt, pr, wpt_commits, message, author, metadata):
# Ensure we have anything in a wpt submodule
git_work_wpt.git.submodule("update", "--init", "--recursive")
dest_path = os.path.join(git_work_gecko.working_dir,
env.config["gecko"]["path"]["wpt"])
src_path = git_work_wpt.working_dir
# Specific paths that should be re-checked out
keep_paths = {"LICENSE", "resources/testdriver_vendor.js"}
# file names that are ignored in any part of the tree
ignore_files = {".git"}
logger.info("Setting wpt HEAD to %s" % wpt_commits[-1].sha1)
git_work_wpt.head.reference = wpt_commits[-1].commit
git_work_wpt.head.reset(index=True, working_tree=True)
# First remove all files so we handle deletion correctly
shutil.rmtree(dest_path)
ignore_paths = defaultdict(set)
for name in keep_paths:
src, name = os.path.split(os.path.join(src_path, name))
ignore_paths[src].add(name)
def ignore_names(src, names):
rv = []
for item in names:
if item in ignore_files:
rv.append(item)
if src in ignore_paths:
rv.extend(ignore_paths[src])
return rv
shutil.copytree(src_path,
dest_path,
ignore=ignore_names)
# Now re-checkout the files we don't want to change
# checkout-index allows us to ignore files that don't exist
git_work_gecko.git.checkout_index(*(os.path.join(env.config["gecko"]["path"]["wpt"], item)
for item in keep_paths), force=True, quiet=True)
allow_empty = False
if not git_work_gecko.is_dirty(untracked_files=True):
logger.info("PR %s didn't add any changes" % pr.number)
allow_empty = True
git_work_gecko.git.add(env.config["gecko"]["path"]["wpt"],
no_ignore_removal=True)
message = sync_commit.Commit.make_commit_msg(message, metadata)
commit = git_work_gecko.index.commit(message=message,
author=git.Actor._from_string(author))
logger.debug("Gecko files changed: \n%s" % "\n".join(list(commit.stats.files.keys())))
gecko_commit = sync_commit.GeckoCommit(self.git_gecko,
commit.hexsha,
allow_empty=allow_empty)
return gecko_commit