diff --git a/source/app.d b/source/app.d index d952688..8289191 100644 --- a/source/app.d +++ b/source/app.d @@ -39,7 +39,15 @@ int main(string[] args) ) ) .add(new Command("status", "Checking the status of tracked files")) - .add(new Command("diff", "Show changed data")) + .add(new Command("diff", "Show changed data") + .add(new Option("s", "snapshot", "Specify snapshot hash") + .optional + .validateEachWith( + opt => opt.isValidHash, + "must contain snapshot hash provided" + ) + ) + ) .add(new Command("size", "Size of snapshots")) .add(new Command("import", "Import snapshot from a tar.gz archive") .add(new Argument("archive", "The path to the tar.gz archive file").required) @@ -167,7 +175,9 @@ int main(string[] args) snag.initialize(init.flag("force")) ) .on("diff", diff => - snag.diff() + snag.diff( + diff.option("snapshot", "") + ) ) .on("size", size => snag.size() diff --git a/source/snag/core/core.d b/source/snag/core/core.d index 4196481..0f97fbe 100644 --- a/source/snag/core/core.d +++ b/source/snag/core/core.d @@ -292,16 +292,41 @@ class Snag { writeln("Backup was restored successfully: ", hash); } - void diff() { - auto result = git( - ["diff"], - "Failed to retrieve changes" - ); - if (result.output.length) { - result.output.write; + void diff(string hash) { + string[] result; + if (hash.length) { + git( + ["rev-parse", hash], + "This snapshot is not available in the archive" + ); + result = git( + ["show", hash, "--name-only", "--pretty="], + "Failed to retrieve snapshot information" + ).output.split('\n').filter!(p => !p.empty).array; + } else { + result = git( + ["diff", "--name-only"], + "Failed to retrieve changes" + ).output.split('\n').filter!(p => !p.empty).array; + } + if (!result.length) { + writeln("No changes at the moment"); return; } - writeln("No changes at the moment"); + if (hash.length) + result.each!(e => + git( + ["show", "--pretty=", hash, "--", e], + "Failed to retrieve file information" + ).output.write + ); + else + result.each!(e => + git( + ["diff", e], + "Failed to retrieve file information" + ).output.write + ); } void exportSnapshot(string path, string hash) {