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.
This commit is contained in:
Andrew Ayer
2013-03-07 15:29:27 -08:00
parent 490b7143b1
commit e184b39eaa
2 changed files with 6 additions and 2 deletions

1
README
View File

@@ -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

View File

@@ -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);