From b07f49b9b37118dd6c8da909c53149b5e085cbf6 Mon Sep 17 00:00:00 2001 From: Andrew Ayer Date: Wed, 6 Aug 2014 19:02:42 -0700 Subject: [PATCH] smudge: if file is not encrypted, just copy through clear text Since Git consults the checked-out .gitattributes instead of the .gitattributes in effect at the time the file was committed, Git may invoke the smudge filter on old versions of a file that were committed without encryption. --- commands.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/commands.cpp b/commands.cpp index 3f8d489..2ee80e1 100644 --- a/commands.cpp +++ b/commands.cpp @@ -579,8 +579,11 @@ int smudge (int argc, const char** argv) unsigned char header[10 + Aes_ctr_decryptor::NONCE_LEN]; std::cin.read(reinterpret_cast(header), sizeof(header)); if (std::cin.gcount() != sizeof(header) || std::memcmp(header, "\0GITCRYPT\0", 10) != 0) { - std::clog << "git-crypt: error: file not encrypted" << std::endl; - return 1; + // File not encrypted - just copy it out to stdout + std::clog << "git-crypt: warning: file not encrypted" << std::endl; // TODO: display additional information explaining why file might be unencrypted + std::cout.write(reinterpret_cast(header), std::cin.gcount()); // include the bytes which we already read + std::cout << std::cin.rdbuf(); + return 0; } return decrypt_file_to_stdout(key_file, header, std::cin); @@ -619,7 +622,7 @@ int diff (int argc, const char** argv) in.read(reinterpret_cast(header), sizeof(header)); if (in.gcount() != sizeof(header) || std::memcmp(header, "\0GITCRYPT\0", 10) != 0) { // File not encrypted - just copy it out to stdout - std::cout.write(reinterpret_cast(header), in.gcount()); // don't forget to include the header which we read! + std::cout.write(reinterpret_cast(header), in.gcount()); // include the bytes which we already read std::cout << in.rdbuf(); return 0; }