aboutsummaryrefslogtreecommitdiffstats
path: root/src
AgeCommit message (Collapse)Author
2020-08-30Increase version v0.1.0 -> v0.2.0v0.2.0Teddy Wing
2020-08-30git-suggestion-cli: Rename crate to `git-suggestion`Teddy Wing
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.
2020-08-30diff_options: Add doc commentsTeddy Wing
2020-08-30diff_options: Sort and uniq `FLAGS`Teddy Wing
Make the list easier to scan by ordering it alphabetically. Also, I noticed there were two `-p` flags listed, so ran the flags through `uniq`.
2020-08-30diff_options::parse(): Rename `found_args` to `diff_args`Teddy Wing
Now that I added `program_args`, reading this back over I realised `found_args` didn't convey enough information about what it contains.
2020-08-30diff_options: Merge `FLAGS` and `OPTIONS`Teddy Wing
Didn't look closely enough in d9b8838a5d99e643a751d042047644cfa4a9a032, but we now have the exact same handling for key-value options and flags.
2020-08-30diff_options: Merge `ARG_OPTIONS` and `OPT_OPTIONS`Teddy Wing
Now that I've confirmed that Git's key value options require an '=' to specify the value, we can drop the distinction between options that require and argument and those that optionally take an argument. Also remove the code that interprets an argument that doesn't start with '-' as the value of the preceding option.
2020-08-30diff_options: Clean up codeTeddy Wing
Remove old process code and comments.
2020-08-29git-sugdiff: Fix output by waiting for child processTeddy Wing
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.
2020-08-29diff_options: Remove non-equals argument value handlingTeddy Wing
Tested out diff arguments with Git, and it turns out that arguments in the following form: $ git diff --word-diff color are not allowed. This error results: fatal: ambiguous argument 'color': unknown revision or path not in the working tree. Use '--' to separate paths from revisions, like this: 'git <command> [<revision>...] -- [<file>...]' Thus, option all arguments require the equals character to specify the value of those arguments. We can make the logic much simpler by eliminating handling of space-separated argument values altogether. This fixes the problem of suggestion positional arguments being misinterpreted as `OPT_OPTIONS` argument values.
2020-08-29git-sugdiff: Use `diff_options.parse()` to extract diff optionsTeddy Wing
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.
2020-08-26Add `diff_options` to parse Git diff optionsTeddy Wing
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.
2020-08-23git-sugdiff: Replace `unwrap`s with proper error handlingTeddy Wing
2020-08-23Rename `git-sugpatch` to `git-sugdiff`Teddy Wing
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.
2020-08-23git-sugdiff: Remove TODOTeddy Wing
This works now, thanks to 3c6f337e26964077d1ce629fa17d16e4484b877f.
2020-08-23Suggestion: Rename `diff_command()` to `blob()`Teddy Wing
This function is no longer calling the `git diff` command, so this name doesn't make sense.
2020-08-23git-sugdiff: Add `--no-pager` to `git diff` commandTeddy Wing
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.
2020-08-23Revert "Suggestion.diff_command: Diff an index instead of a file"Teddy Wing
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.
2020-08-23Suggestion.diff_command: Diff an index instead of a fileTeddy Wing
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.
2020-08-22Suggestion.diff_command: Return the right side version blobTeddy Wing
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.
2020-08-22Execute `git diff` to output diffsTeddy Wing
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.
2020-08-06Rename the project `git-suggestion`Teddy Wing
Since this is a Git command, this makes more sense to me.
2020-08-05OwnerRepo: Remove ".git" suffix from HTTPS URLsTeddy Wing
I hadn't tested with HTTPS remote URLs, so assumed the code I copied from `github_suggestion::url` would work. It worked for suggestion comment URLs, but it doesn't work for remote URLs because the latter end in ".git". Remove this suffix to fix the bug.
2020-08-04Add license (GNU GPLv3+)Teddy Wing
2020-08-03Config: Add a version argumentTeddy Wing
Allow getting the program version from the command line.
2020-08-02Remove `main.rs`Teddy Wing
We have multiple binaries in `src/bin/`, so this file is no longer needed.
2020-08-02Add documentation commentsTeddy Wing
Light documentation for our various functions and types.
2020-08-02Move suggestion arguments check to `Config::get`Teddy Wing
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.
2020-08-02git-sugapply: Copy over new logic from `git-sugpatch`Teddy Wing
Use the new logic from `git-sugpatch` to build a `Config` and run `apply()` on all suggestion input arguments.
2020-08-02Config: Add description to `--github-token` argumentTeddy Wing
2020-08-02Config: Add description to `--remote` argumentTeddy Wing
2020-08-02Add `-h` argumentTeddy Wing
Print usage on `-h` and `--help`. Store the usage brief on `Config` in order to be able to print it from multiple places.
2020-08-02git-sugpatch: Print usage with no suggestion argumenetTeddy Wing
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`.
2020-08-02Config: Remove old lineTeddy Wing
This was a test, before I worked out the API for this function.
2020-08-02git-sugpatch: Exit with `EX_USAGE` if no suggestion argumentsTeddy Wing
Replace my test exit code with a real one.
2020-08-02git-sugpatch: Replace `unwrap` with printed error message and exitTeddy Wing
2020-08-02for_suggestion: Replace `unwrap`s with exitsTeddy Wing
Print the error and exit.
2020-08-02lib.rs: Make `owner_repo` module privateTeddy Wing
Turns out this didn't need to be public at all.
2020-08-02git-sugpatch: Move the suggestion arguments loop to a new functionTeddy Wing
Split this out into a separate function because I want to reuse it in `git-sugapply`.
2020-08-02git-sugpatch: Fix `SuggestionUrl` parsingTeddy Wing
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.
2020-08-02lib.rs: Make `owner_repo` `pub(crate)` againTeddy Wing
Made this `pub` for one of the test tries in 38a871f28bad90e238021d8cc46b9fa926f9df75, but in the end it wasn't necessary. Restore this to the prior visibility.
2020-08-02config::Error::EnvVar: Include the variable name in the error messageTeddy Wing
The source error's message doesn't include the name. Ensure we print the name of the variable we're trying to get so that users know which one is missing.
2020-08-02config::Error::Opts: Include source error in messageTeddy Wing
Ensure the source error is surfaced.
2020-08-02git-sugpatch: Clean up after 38a871f28bad90e238021d8cc46b9fa926f9df75Teddy Wing
Remove unused code.
2020-08-02git-sugpatch: Error if no remote and suggestion ID argumentTeddy Wing
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.
2020-08-02git-sugpatch: Print error and exit on `Config::get` errorTeddy Wing
Add `exitcode` to exit with an appropriate code. Add the `gseprintln` macro to wrap `eprintln!()`, prefixing the output with "error: ".
2020-08-02git-sugpatch: Accept multiple suggestion args; Accept suggestion ID argsTeddy Wing
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
2020-08-01Config: Add suggestion argumentsTeddy Wing
Store the suggestion references specified on the command line.
2020-08-01OwnerRepo: Parse from SSH-style pathsTeddy Wing
Remotes can be HTTP URLs or use SSH/SCP-style paths like: git@github.com/teddywing/github-suggestion.git We need to handle both regular URLs and the above style, which isn't parseable by the 'url' crate. Add a custom parsing function to get the owner and repo from this format. When trying to parse `OwnerRepo` from a string, first try to parse it as a URL. If that fails with a `RelativeUrlWithoutBase` error, assume it's the other style of reference.
2020-08-01Config: Extract `remote` into functionTeddy Wing