Age | Commit message (Collapse) | Author |
|
Now that I'm using the name "git-suggestion" in a few places, and from a
user perspective, it's more Git-oriented than GitHub-oriented, I think
the crate should be renamed to reflect that.
|
|
Remove old process code and comments.
|
|
I thought I'd resolved this problem by adding the `--no-pager` flag in
76079daf1e2175d02c9c584e47a21650fce30bb6, but it turns out that didn't
fix it.
When running the command, I'd get the following output, with the shell
prompt preceding the start of the diff, and the command hanging without
exiting to a new prompt line until a new interaction:
$ ./target/debug/git-sugdiff 459692838
$ diff --git a/src/server.rs b/44ff3b520321467a9220965d13f997690ff3fda7
index d9eee95..44ff3b5 100644
--- a/src/server.rs
+++ b/44ff3b520321467a9220965d13f997690ff3fda7
@@ -73,7 +73,7 @@ impl Server {
internal_server_error(&mut raw_request.stdout())
},
Error::ConduitResponse { .. } => {
error!("Error [-getting-]{+from+} response: {}", e);
internal_server_error(&mut raw_request.stdout())
},
Turns out I need to wait for the command to exit in order to properly
execute the external command.
|
|
Config::get():
Change `args` type so we can pass both a `Vec<String>` and
`Vec<&String>`.
diff_options.parse():
* Split diff arguments and program arguments by returning a tuple.
* Exit the args loop once we've parsed an argument.
* Update test
* Add a non-working test for suggestion arguments. An `OPT_OPTIONS`
argument could be followed by an argument that's not the value of the
`OPT_OPTIONS` option. Currently, that arg will always be parsed as the
value. We need to handle this case.
|
|
In order to accept Git diff options on the command line, we need a way
to extract these from args.
Add a function to parse diff options. These were sourced from:
https://github.com/git/git/blob/675a4aaf3b226c0089108221b96559e0baae5de9/Documentation/diff-options.txt
The function loops through the input arguments and extracts all diff
options and their values.
Still needs some work to integrate it into `git-sugdiff`, but it
currently works as advertised.
|
|
|
|
The word "patch" reminds me more of the `patch` Unix command, which is
what `git-sugapply` does.
Since this command outputs diffs, it makes more sense to call it
`sugdiff`. That also brings these closer to the native Git commands,
`git-diff` and `git-apply`.
I had chosen "patch" originally because the command generated a unified
diff that could be used as a patch file to apply to the repo.
|
|
This works now, thanks to 3c6f337e26964077d1ce629fa17d16e4484b877f.
|
|
This function is no longer calling the `git diff` command, so this name
doesn't make sense.
|
|
The diff command wasn't exiting after outputting the diff. Add the
`--no-pager` argument to ensure that the pager doesn't activate. This
also seems to cause the command to exit once all the output is printed.
We don't want the pager because we need to call `git diff` for each
suggestion. If an early diff took up more than a page and activated the
pager, that would block the next diffs from appearing. We want them all
to appear at once.
|
|
This reverts commit 588cd526fd78b3a0e0ec1dfb9fc194ca385de902.
Since each suggestion has its own associated commit, we can't compare a
tree and a single commit. We'll probably have to invoke `git diff` once
for each suggestion.
|
|
This will enable us to use the `git diff` command with more than one
suggestion at the same time.
We compare the commit of the suggestion with the new index's tree.
And as I write this, I'm realising that we can't diff multiple
suggestions using the same commit because each suggestion has its own
commit.
Need to work out a different way to do this.
|
|
Don't run the `git diff` command in this function, instead return the
new blob created for the right hand side of the comparison.
This will facilitate showing the diffs of multiple suggestions at once.
Maybe. I haven't tried the command yet.
Actually, looking at the man page, it doesn't say we can include more
than one blob pair, so I might need to put all of the suggestion changes
into a single blob and compare the original commit with that.
|
|
I want to enable colour diff output. At first, I thought about doing
this by getting the diff colours from the Git config, then outputting
the ANSI escape codes manually with the text.
However, I then thought it would be nice to enable other diff features
like `--word-diff`, and it would be too much trouble to re-implement
that manually, and then I'd have to take word diff colouring into
account.
Decided that the optimal way to get both colours and extra diff
features like word diffing would be to use `git diff` directly under the
hood.
We shell out to `git diff`, and give it the original file as a base, and
a new blob object that we create in the repository on the right side.
This allows us to compare the file using a command in the following
format:
$ git diff <BASE>:src/server.rs <TEMPORARY_HASH>
Ostensibly, the temporary blob object I create for the right side
version should be freed automatically by `git2`.
Add a new `sugdiff` command to output diffs. This will replace
`sugpatch`. Since we're working with diffs, I think a name with "diff"
sounds more logical. The previous version, "patch" sounds too much like
what "apply" does, because of the Unix `patch` command.
|
|
|
|
Since this check for suggestion arguments is in both binaries, we can
move it to the common preflight function.
Clean up other areas now that we moved the function.
|
|
Use the new logic from `git-sugpatch` to build a `Config` and run
`apply()` on all suggestion input arguments.
|
|
Print usage on `-h` and `--help`.
Store the usage brief on `Config` in order to be able to print it from
multiple places.
|
|
Add `Options` to `Config` to allow us to get a usage string from a
`Config` instance, which is where we create `Options`.
Needed to remove the `Debug` derive on `Config` in order to add the
field as `Options` doesn't implement `Debug`.
|
|
Replace my test exit code with a real one.
|
|
|
|
Split this out into a separate function because I want to reuse it in
`git-sugapply`.
|
|
Forgot to change this line when I set up the loop over suggestion
arguments. We want to parse the current argument instead of hard-coding
the first one.
|
|
Remove unused code.
|
|
We want to allow not having a remote when URL arguments are given, but
require it when a suggestion ID argument is given (otherwise we wouldn't
have an owner-repo pair to make the GitHub request).
Had some trouble with the `OwnerRepo.o_r` value. It was being moved into
the closure, so tried a loop. There was a similar problem with the loop.
However, by returning, I was able to get a reference to the `Result`
instead of having it be moved.
|
|
Add `exitcode` to exit with an appropriate code.
Add the `gseprintln` macro to wrap `eprintln!()`, prefixing the output
with "error: ".
|
|
Add the ability to pass multiple suggestions to the binary. The diffs
will appear in the output one after another.
Also allow suggestions to be specified by their comment ID instead of
their full URL. This uses the Git repo's remote to determine the
owner-repo pair. When a URL argument is given, the owner-repo pair is
extracted from the URL.
It's now possible to call the binary like this:
$ git-sugpatch 459692838 \
> https://github.com/teddywing/suggestion-test/pull/1#discussion_r459691747
|
|
We need the following values in order to build a `Client`:
* GitHub token
* Repo owner
* Repo name
Get the token from a command-line argument, or else the Git config, or
else an environment variable.
Get the repo identifiers from the repo's remote URL. Use the remote
specified as a command-line argument, otherwise get it from the Git
config, or else default to "origin".
TODO: Only try to get the owner-name pair from the remote if a comment
ID was given, not if a URL argument was passed.
|
|
Didn't like the old name. Wanted to make the GitHub reference more
explicit. I remember it as "suggestion", since that's the name of the
GitHub feature, so "suggested" was confusing. The final "patch" seemed
redundant or unnecessary.
|
|
Extend the `Error` enum with new variants to capture the possible errors
from `diff()` and `diff_with_repo()`.
|
|
Wrap `Github` client errors.
|
|
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.
|
|
An executable to apply a suggested change to the appropriate file in the
repo.
Add a new `SuggestionUrl` type that allows us to extract the necessary
data to fetch a suggestion comment from the GitHub API using a GitHub
pull request comment URL.
|