From e184b39eaa01ea8d7964e46703d1f8832e943a21 Mon Sep 17 00:00:00 2001 From: Andrew Ayer Date: Thu, 7 Mar 2013 15:29:27 -0800 Subject: [PATCH] git-crypt init: Ignore untracked files when running git status Untracked files are not touched by git reset, so git-crypt init is safe even with untracked files present. This relies on the -u option to git-status, which was added in Git 1.6.0, which was released in 2008. Add Git 1.6.0 as a requirement in the README. --- README | 1 + commands.cpp | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/README b/README index 9565263..039021e 100644 --- a/README +++ b/README @@ -31,6 +31,7 @@ DEPENDENCIES To use git-crypt, you need: + * Git 1.6.0 or later * OpenSSL * For decrypted git diff output, Git 1.6.1 or later * For decrypted git blame output, Git 1.7.2 or later diff --git a/commands.cpp b/commands.cpp index fcd5851..2fd6df2 100644 --- a/commands.cpp +++ b/commands.cpp @@ -195,10 +195,13 @@ void init (const char* argv0, const char* keyfile) // 0. Check to see if HEAD exists. See below why we do this. bool head_exists = system("git rev-parse HEAD >/dev/null 2>/dev/null") == 0; - // 1. Make sure working directory is clean + // 1. Make sure working directory is clean (ignoring untracked files) + // We do this because we run 'git reset --hard HEAD' later and we don't + // want the user to lose any changes. 'git reset' doesn't touch + // untracked files so it's safe to ignore those. int status; std::string status_output; - status = exec_command("git status --porcelain", status_output); + status = exec_command("git status -uno --porcelain", status_output); if (status != 0) { std::clog << "git status failed - is this a git repository?\n"; std::exit(1);