init: skip git reset if HEAD doesn't exist

This could happen if repo is brand-new with no files.
This commit is contained in:
Andrew Ayer
2012-07-06 16:03:30 -07:00
parent 6e3dd5a8d3
commit fab7860109

View File

@@ -170,7 +170,9 @@ void init (const char* argv0, const char* keyfile)
// 3. Do a hard reset so any files that were previously checked out encrypted
// will now be checked out decrypted.
if (system("git reset --hard") != 0) {
// If HEAD doesn't exist (perhaps because this repo doesn't have any files yet)
// just skip the reset.
if (system("! git show-ref HEAD > /dev/null || git reset --hard HEAD") != 0) {
std::clog << "git reset --hard failed\n";
std::exit(1);
}