Compare commits

...
Sign in to create a new pull request.

1 commit

2 changed files with 45 additions and 10 deletions

View file

@ -39,7 +39,15 @@ int main(string[] args)
) )
) )
.add(new Command("status", "Checking the status of tracked files")) .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("size", "Size of snapshots"))
.add(new Command("import", "Import snapshot from a tar.gz archive") .add(new Command("import", "Import snapshot from a tar.gz archive")
.add(new Argument("archive", "The path to the tar.gz archive file").required) .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")) snag.initialize(init.flag("force"))
) )
.on("diff", diff => .on("diff", diff =>
snag.diff() snag.diff(
diff.option("snapshot", "")
)
) )
.on("size", size => .on("size", size =>
snag.size() snag.size()

View file

@ -292,16 +292,41 @@ class Snag {
writeln("Backup was restored successfully: ", hash); writeln("Backup was restored successfully: ", hash);
} }
void diff() { void diff(string hash) {
auto result = git( string[] result;
["diff"], if (hash.length) {
"Failed to retrieve changes" git(
["rev-parse", hash],
"This snapshot is not available in the archive"
); );
if (result.output.length) { result = git(
result.output.write; ["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; 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) { void exportSnapshot(string path, string hash) {