open(".git/WIZARD_SIZE", "w").write(str(scripts.get_disk_usage()))
if options.log_file:
open(".git/WIZARD_LOG_FILE", "w").write(options.log_file)
- perform_merge(sh, repo, d, wc, version, use_shm, kib_limit and kib_limit - kib_usage or None)
+ temp_wc_dir = perform_merge(sh, repo, d, wc, version, use_shm, kib_limit and kib_limit - kib_usage or None, options.non_interactive)
+ wc.location = temp_wc_dir
# variables: version, user_commit, next_commit, temp_wc_dir
with util.ChangeDirectory(temp_wc_dir):
try:
finally:
if use_shm and temp_dir and os.path.exists(temp_dir):
shutil.rmtree(temp_dir)
+ if not options.non_interactive:
+ print "Upgrade complete"
def perform_restore(d, backup):
# You don't want d.restore() because it doesn't perform
sh.call("git", "clone", "-q", "--shared", ".", temp_wc_dir)
return temp_dir, temp_wc_dir
-def perform_merge(sh, repo, d, wc, version, use_shm, kib_avail):
+def perform_merge(sh, repo, d, wc, version, use_shm, kib_avail, non_interactive):
# Note: avail_quota == None means unlimited
# naive merge algorithm:
# sh.call("git", "merge", "-m", message, "scripts/master")
if wc.resolveConflicts():
logging.info("Resolved conflicts with application specific knowledge")
sh.call("git", "commit", "-a", "-m", "merge")
- return
+ return os.getcwd()
# XXX: Maybe should recalculate conflicts
logging.info("Conflict info:\n" + sh.eval("git", "diff"))
curdir = mv_shm_to_tmp(curdir, use_shm)
- print "%d %s" % (conflicts, curdir)
- raise MergeFailed
+ os.chdir(curdir)
+ open(os.path.join(d.location, ".scripts/pending"), "w").write(curdir)
+ if non_interactive:
+ print "%d %s" % (conflicts, curdir)
+ raise MergeFailed
+ else:
+ user_shell = os.getenv("SHELL")
+ if not user_shell: user_shell = "/bin/bash"
+ while 1:
+ print
+ print "ERROR: The merge failed with %d conflicts in these files:" % conflicts
+ print
+ outlines = sh.eval("git", "ls-files", "--unmerged").splitlines()
+ files = set()
+ for line in outlines:
+ _, _, _, name = line.split(None, 3)
+ files.add(name)
+ for file in sorted(files):
+ print " * %s" % file
+ print
+ print "Please resolve these conflicts (edit and then `git add`), and"
+ print "then type 'exit'."
+ sh.call(user_shell, "-i", interactive=True)
+ if sh.eval("git", "ls-files", "--unmerged").strip():
+ print
+ print "WARNING: There are still unmerged files."
+ out = raw_input("Continue editing? [y/N]: ")
+ if out == "y" or out == "Y":
+ continue
+ else:
+ print "Aborting. The conflicted working copy can be found at:"
+ print
+ print " %s" % os.getcwd()
+ print
+ print "and you can resume the upgrade process by running in that directory:"
+ print
+ print " wizard upgrade --continue"
+ sys.exit(1)
+ break
+ return os.getcwd()
def mv_shm_to_tmp(curdir, use_shm):
if not use_shm: return curdir
"resolved using the current working directory as the resolved copy.")
parser.add_option("--force", dest="force", action="store_true",
default=False, help="Force running upgrade even if it's already at latest version.")
+ parser.add_option("--non-interactive", dest="non_interactive", action="store_true",
+ default=False, help="Don't drop to shell in event of conflict.")
baton.push(parser, "srv_path")
options, args = parser.parse_all(argv)
if len(args) > 1: