From c2de1e21948d8ac359e3a4bad7f73f3c00292834 Mon Sep 17 00:00:00 2001 From: Andrew Ayer Date: Sat, 7 Feb 2015 13:27:58 -0800 Subject: [PATCH] Add --force option to 'git-crypt lock' It will force a lock even if working directory is unclean. Useful for deconfiguring git-crypt if you've accidentally unlocked with the wrong key or gotten into a similarly sticky situation. --- commands.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/commands.cpp b/commands.cpp index 51c0c43..342ba15 100644 --- a/commands.cpp +++ b/commands.cpp @@ -919,19 +919,23 @@ void help_lock (std::ostream& out) // |--------------------------------------------------------------------------------| 80 chars out << "Usage: git-crypt lock [OPTIONS]" << std::endl; out << std::endl; - out << " -a, --all Lock all keys, instead of just the default" << std::endl; - out << " -k, --key-name KEYNAME Lock the given key, instead of the default" << std::endl; + out << " -a, --all Lock all keys, instead of just the default" << std::endl; + out << " -k, --key-name KEYNAME Lock the given key, instead of the default" << std::endl; + out << " -f, --force Lock even if unclean (you may lose uncommited work)" << std::endl; out << std::endl; } int lock (int argc, const char** argv) { const char* key_name = 0; - bool all_keys = false; + bool all_keys = false; + bool force = false; Options_list options; options.push_back(Option_def("-k", &key_name)); options.push_back(Option_def("--key-name", &key_name)); options.push_back(Option_def("-a", &all_keys)); options.push_back(Option_def("--all", &all_keys)); + options.push_back(Option_def("-f", &force)); + options.push_back(Option_def("--force", &force)); int argi = parse_options(options, argc, argv); @@ -955,9 +959,10 @@ int lock (int argc, const char** argv) std::stringstream status_output; get_git_status(status_output); - if (status_output.peek() != -1) { + if (!force && status_output.peek() != -1) { std::clog << "Error: Working directory not clean." << std::endl; std::clog << "Please commit your changes or 'git stash' them before running 'git-crypt lock'." << std::endl; + std::clog << "Or, use 'git-crypt lock --force' and possibly lose uncommitted changes." << std::endl; return 1; }