- files.add(status.split()[-1])
- for file in files:
- # check for newline mismatch
- # HACK: using git diff to tell if files are binary or not
- if not len(shell.eval("git", "diff", file).splitlines()) == 1 and util.mixed_newlines(file):
- # this code only works on Unix
- def get_newline(filename):
- f = open(filename, "U")
- # for some reason I need two
- s = f.readline()
- if s != "" and f.newlines is None:
- f.readline()
- if not isinstance(f.newlines, str):
- raise Exception("Assert: expected newlines to be string, instead was %s in %s" % (repr(f.newlines), file))
- return f.newlines
- def create_reference(id):
- f = tempfile.NamedTemporaryFile(prefix="wizardResolve", delete=False)
- shell.call("git", "cat-file", "blob", ":%d:%s" % (id, file), stdout=f)
- f.close()
- return get_newline(f.name), f.name
- def convert(filename, dest_nl):
- contents = open(filename, "U").read().replace("\n", dest_nl)
- open(filename, "wb").write(contents)
- logging.info("Mixed newlines detected in %s", file)
- common_nl, common_file = create_reference(1)
- our_nl, our_file = create_reference(2)
- their_nl, their_file = create_reference(3)
- remerge = False
- if common_nl != their_nl:
- # upstream can't keep their newlines straight
- logging.info("Converting common file (1) from %s to %s newlines", repr(common_nl), repr(their_nl))
- convert(common_file, their_nl)
- remerge = True
- if our_nl != their_nl:
- # common case
- logging.info("Converting our file (2) from %s to %s newlines", repr(our_nl), repr(their_nl))
- convert(our_file, their_nl)
- remerge = True
- if remerge:
- logging.info("Remerging %s", file)
- with open(file, "wb") as f:
- try:
- shell.call("git", "merge-file", "--stdout", our_file, common_file, their_file, stdout=f)
- logging.info("New merge was clean")
- shell.call("git", "add", file)
- continue
- except shell.CallError:
- pass
- logging.info("Merge was still unclean")
- else:
- logging.warning("Mixed newlines detected in %s, but no remerge possible", file)
+ mode, hash, role, name = status.split()
+ files.setdefault(name, set()).add(int(role))
+ for file, roles in files.items():
+ # some automatic resolutions
+ if 1 not in roles and 2 not in roles and 3 in roles:
+ # upstream added a file, but it conflicted for whatever reason
+ shell.call("git", "add", file)
+ continue
+ elif 1 in roles and 2 not in roles and 3 in roles:
+ # user deleted the file, but upstream changed it
+ shell.call("git", "rm", file)
+ continue