X-Git-Url: https://scripts.mit.edu/gitweb/wizard.git/blobdiff_plain/193c996c0df943f6bd955bdb475548b04ec9e711..43b45d678fe3d445b0ba6b32ef5605f215cd7d10:/lib/wizard/command/migrate.py diff --git a/lib/wizard/command/migrate.py b/lib/wizard/command/migrate.py index dbf93d3..056d448 100644 --- a/lib/wizard/command/migrate.py +++ b/lib/wizard/command/migrate.py @@ -85,6 +85,8 @@ what repository and tag to use.""" parser = WizardOptionParser(usage) parser.add_option("--dry-run", dest="dry_run", action="store_true", default=False, help="Prints would would be run without changing anything") + parser.add_option("--force", "-f", dest="force", action="store_true", + default=False, help="If .git or .scripts directory already exists, delete them and migrate") options, args, logger = parser.parse_all(argv, logger) if len(args) > 1: parser.error("too many arguments") @@ -99,8 +101,16 @@ what repository and tag to use.""" elif e.errno == 2: raise NoSuchDirectoryError(dir) else: raise e - if os.path.isdir(".git"): - raise AlreadyMigratedError(dir) + if os.path.isdir(".git") or os.path.isdir(".scripts"): + if not options.force: + raise AlreadyMigratedError(dir) + else: + if os.path.isdir(".git"): + logger.warning("Force removing .git directory") + if not options.dry_run: shutil.rmtree(".git") + if os.path.isdir(".scripts"): + logger.warning("Force removing .scripts directory") + if not options.dry_run: shutil.rmtree(".scripts") try: deploy = wd.Deployment.fromDir(".") version = deploy.getAppVersion() @@ -128,7 +138,7 @@ what repository and tag to use.""" did_git_checkout_scripts = False try: # create repository - shell.call("git", "init") + shell.call("git", "--git-dir=.git", "init") did_git_init = True # configure our remote shell.call("git", "remote", "add", "origin", repo) @@ -138,18 +148,18 @@ what repository and tag to use.""" # perform the initial fetch shell.call("git", "fetch", "origin") # soft reset to our tag - shell.call("git", "reset", tag) + shell.call("git", "reset", tag, "--") # checkout the .scripts directory shell.call("git", "checkout", ".scripts") did_git_checkout_scripts = True # XXX: setup .scripts/version??? # for verbose purposes, give us a git status and git diff - raise NotImplementedError if options.verbose: shell.call("git", "status") shell.call("git", "diff") except: - logger.error("ERROR: Exception detected! Rolling back...") + # this... is pretty bad + logger.critical("ERROR: Exception detected! Rolling back...") if did_git_init: shell.call("rm", "-Rf", ".git") if did_git_checkout_scripts: