diff options
author | Teddy Wing | 2020-07-26 18:17:11 +0200 |
---|---|---|
committer | Teddy Wing | 2020-07-26 18:17:11 +0200 |
commit | 1d15f9739f690f2e7afbb2bf868be74044ab3f30 (patch) | |
tree | ee40d91d56c475b84424e3f3bb9b70a0f775ee7e /src/bin | |
parent | ced76c1ffce4da1dfcf286b3ef358c0662f6b5a1 (diff) | |
download | git-suggestion-1d15f9739f690f2e7afbb2bf868be74044ab3f30.tar.bz2 |
Suggestion: Add `diff` method
Create a patch file for the suggestion. Instead of building the patch
text manually, as in my earlier attempts (`patch` and `unified_diff`),
apply the patch to the file in memory, and then ask libgit2 to give us a
Git patch by comparing the original blob and the patched buffer.
Doing this because I was unsuccessful in manually composing a patch file
that Git would accept. I could create unified diffs that the `patch`
program would accept, but these wouldn't work with `git-apply`. My
current guess is that these didn't work because I didn't have both
before and after context in my manually-created patch files.
Since this tool is intended to be used with Git, I want a patch file
that will work transparently with Git utilities. The easiest alternative
to manually generating the patch file seemed to be to have Git create
the patch text.
Add a new binary, `git-sugpatch`, that outputs the patch text to
standard output.
TODO: This gets the original from the current HEAD in `apply_to()`. We
should instead be using the contents of `blob`, because the original is
not necessarily the working copy.
Diffstat (limited to 'src/bin')
-rw-r--r-- | src/bin/git-sugpatch.rs | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/bin/git-sugpatch.rs b/src/bin/git-sugpatch.rs new file mode 100644 index 0000000..08d1a38 --- /dev/null +++ b/src/bin/git-sugpatch.rs @@ -0,0 +1,25 @@ +use std::env; +use std::process; + +use git_suggested_patch::{Client, SuggestionUrl}; + + +fn main() { + let args: Vec<_> = env::args().collect(); + + if args.len() < 2 { + process::exit(111); + } + + let url: SuggestionUrl = args[1].parse().unwrap(); + + let client = Client::new( + env!("GITHUB_TOKEN"), + &url.owner, + &url.repo, + ); + + let suggestion = client.fetch(&url.comment_id).unwrap(); + + print!("{}", suggestion.diff()); +} |