Commit graph

59 commits

Author SHA1 Message Date
sandroid 5306146aa1
Add a preview to _forgit_clean 2024-04-09 23:12:19 +02:00
sandr01d 1c34d0d54d
Fix ga, gsp & gcf with older git versions (#335)
Removes the usage of --pathspec-file-nul (which is not available in older git versions) in favor of storing the file names passed to the git command in an array instead of a string.
2024-04-09 22:43:24 +02:00
sandr01d 131f2c1f66
Fix: Pager variables are not evaluated (#381)
Reintroduces the usage of eval for evaluating pagers. We removed all usage of eval with #326, which broke code defined by users in the $FORGIT_*_PAGER environment variables and git pagers. In this particular case, eval does exactly what we want, since we do want to execute code that is defined by the user outside of forgit.
2024-04-09 22:37:29 +02:00
sandr01d cac700ebe1
Refactor: Do not ignore shellcheck 2207 (#378)
We sometimes capture multiline output in an array. We used to do so
directly, while setting IFS to "\n" to control splitting. This has the
downside that bashs glob expansion will be invoked.
Use read -r in such cases to add each line into the array without glob
expansion.
2024-04-05 20:12:32 +02:00
sandr01d 7690364a98
Fix preview for deleted files in _forgit_stash_push (#336) 2024-03-31 00:48:18 +01:00
sandr01d 032b52f6d5
Fix branch preview for branches that have the same name as a file (#374)
The preview for branches (when using gbd or gcb) did not work for branches that have the same name as a file in the repository. This commit fixes this behavior by separating files and revisions with '--' as git suggests, while leaving the files blank to keep matching all files.
2024-03-31 00:31:48 +01:00
sandr01d 1a1153978f
Refactor: Quote variables in preview of _forgit_diff, _forgit_reset_head & _forgit_cherry_pick_form_branch (#372) 2024-03-31 00:30:00 +01:00
sandr01d d582f2aa0b
Fix _forgit_diff on macOS (#375)
In bash 3.2 uninitialized arrays contain one entry: an empty string,
whereas in modern versions of bash they do not contain any entry. Make
sure the $commits and $files arrays are explicitly initialized as empty
arrays to allow git to fall back to diffing local changes instead of
trying to diff against a revision with a name of an empty string.
2024-03-27 20:36:07 +01:00
sandroid 0a8a70bc20 Refactor: Quote files passed to preview functions
In some cases we need to pass multiple files to preview functions. These
files are treated as a single string that is evaluated by fzf and passed
on to our preview functions as individual arguments.
This commit introduces a _forgit_quote_files function that ensures the
resulting arguments are quoted properly.
2024-03-24 15:50:40 +01:00
sandroid 0c0668f57b Refactor: Replace deferred extract variable in _forgit_add with a call to _forgit_get_single_file_from_add_line 2024-03-24 15:50:40 +01:00
sandroid 0b7f1f47f5 Refactor: Replace _forgit_extract_sha variable with function
We used to store code that extracts the commit hash from a line in a
variable. This commit replaces this variable with a function.
2024-03-24 15:50:40 +01:00
sandroid 67d6d8508f Refactor: Replace deferred code in yank commands with functions
Many commands allow copying the commit hash or stash name of the current
selection to the clipboard. We previously used deferred code to do so.
This commit replaces the deferred code and binds these commands to
functions instead.
2024-03-24 15:50:40 +01:00
sandroid d8fe39c893 Refactor: Replace deferred code in edit commands with functions
_forgit_diff and _forgit_add allow editing the currently previewed file
in the EDITOR. This used to be handled entirely using deferred code.
This commit replaces the deferred code and binds the commands to functions
instead.
2024-03-24 15:50:40 +01:00
sandroid 35a4ce33ec Refactor: Replace deferred code in enter commands with functions
In _forgit_log and _forgit_enter it is possible to diff a single
commit/file by pressing enter. We used to store the code that executes
the diffs in variables and passed it to fzf as deferred code. This
refactor reduces the amount of deferred code by using functions instead
of variables.
2024-03-24 15:50:40 +01:00
sandroid ab1116da0e Refactor: Replace deferred git commands with regular git commands
We were using deferred code in git commands in some places without any
reason. Each of these deferred code snippets was only executed a
single time, so we can replace them with regular git commands.

This commit changes how we handle the FORGIT_LOG_GRAPH_ENABLE
environment variable. We previously used a variable that stored the
--graph flag as a string and unset it, when FORGIT_LOG_GRAPH_ENABLE
was set to anything other than true. We now create an empty array and
add the --graph flag to it when FORGIT_LOG_GRAPH_ENABLE is unset or true.
Doing it this way allows us to build a command line without having to use
eval. The outcome is the same as before.
2024-03-24 15:50:40 +01:00
sandroid 61db097bad Refactor: Replace _forgit_emojify deferred code variable with a function
We used to have a variable that was either undefined or contained a
piece of deferred code that piped input through emojify when present
on the system. To remove the deferred code here, this commit
replaces the _forgit_emojify variable with a function that either pipes
the input through emojify or through cat, depending on whether emojify
is present.
2024-03-24 15:50:40 +01:00
sandroid f927c223f3 Refactor: Move git commands from deferred code into functions
We often used deferred code to encapsulate git commands and make them
reusable.
This change removes deferred code for git commands and replaces it with
functions instead.
Some of the deferred code was used with xargs, which executes it on a
subshell. To avoid having to expose the new git functions the same way
we do with the preview functions, the usage of xargs in these cases is
replaced with either a loop or a single command when possible.
2024-03-24 15:50:40 +01:00
sandroid bfffda68d8 Refactor: Replace deferred code used for fzf preview with functions
Removes the deferred code that is used for creating the fzf preview functions and replaces it with _forgit_*_preview functions instead. These functions are exposed as forgit commands so they can be invoked from the fzf subshell. We split the exposed commands into public_commands and private_commands. The only difference between them is that public_commands are mentioned in the help text.
This commit changes the flags variable in _forgit_blame from a string to an array. This is necessary to allow the flags to be passed to _forgit_blame_preview as individual arguments.
2024-03-24 15:50:40 +01:00
sandroid b41e4ff1b4 Refactor: Parse environment variables into arrays
Forgit allows specifying git options in environment variables that are passed along to the individual git commands. We currently treat those as strings. This commit adds a _forgit_parse_array function and uses it to parse all such environment variables into arrays instead. This will allow us to get rid of deferred code, since we can pass the parsed arrays directly to the git commands and don't have to rely on eval.
2024-03-24 15:50:40 +01:00
Chris Apple 2436fc4e11
Fix issue where diff preview was broken on mac (#365)
Closes #362
2024-03-14 06:55:17 -07:00
sandr01d 07f7e4350b
Fix diff preview and edit for files with a ']' character in their name (#354)
Our sed command for removing the short status (e.g. [M]) from gits
output to extract the file name with _forgit_diff matched until the
last ']' character in the line due to sed being greedy. This created
issues with file names that contain a ']' character.
To fix this, I made sure that only the short status is removed by sed,
independently of the file name.
2024-02-28 21:01:56 +01:00
Hoang Nguyen 2eda2a457a
fix: keep the script compatible with Busybox applets (#345)
Use short flags for sort command
    Remove -n flag for nl command. The numbers in the selection list won't be aligned anymore, but no information is lost.

The current arguments are only presented in GNU's coreutils.
2024-02-05 21:17:16 -08:00
sandr01d 48e91dadb5
Fixed opening files in the editor when a path contains spaces or a file was renamed (#323)
Fixed two issues that occurred when trying to open files in the editor (ctrl+e). In both cases the wrong files were opened.

1. Files that have spaces in their path. I fixed this by properly escaping the variables used in _forgit_diff() and forgit_add().
2. When a tracked file was renamed and added, trying to open it in the editor from the diff view, would open a file with a name that consists of both, the old and the new name. I added a separate sed command that can handle this special case.
2023-08-27 17:06:30 +02:00
Tim e8e308340a
checkout_branch: support "-" argument (#322)
git natively supports `-` as an argument to `git switch` and `git
checkout`. It is shorthand for `@{-1}`, which is a way to refer to the
last branch you were on.

forgit used to interpret `-` as a branch name, detect that it does not
exist yet and create a new one with this name, which does not work.

Add a check whether `-` is passed on the command line and do not create
a new branch in this case
2023-08-13 08:15:19 +02:00
sandr01d 9b5714fcde
Do not hide error messages when trying to return early (#318)
Most of forgits functions allow to invoke git directly when arguments were passed. In most of these functions we only return early when the git command that is executed returns successfully. This hides error messages from the user. As discussed with @carlfriedrich in #316, I've modified this behavior to also return early when the git command was not successful, so we're transparent about gits error messages and return values. This also fixes an infinite loop printing an error message when invalid arguments were passed to gsp. Because gbl and gclean allow passing arguments to the git command that is invoked when we don't return early, I've modified their behavior to only invoke git directly (and return early) in the case that non flag arguments were passed.
I've also modified gclean to use the -q flag instead of piping it's output to /dev/null.
2023-08-06 16:50:25 +02:00
sandr01d 8547b554c8
Make gclean parameters consistent (#317) 2023-07-06 20:13:03 +02:00
Wenxuan c78c10a028
feat: add a keybind to open current file in editor (#313)
* feat: add a keybind to open current file in default editor

---------

Signed-off-by: Wenxuan Zhang <wenxuangm@gmail.com>
Co-authored-by: sandr01d <88739791+sandr01d@users.noreply.github.com>
2023-06-19 09:26:07 +08:00
sandr01d 665e3fd215
Allow passing parameters to branch_delete and stash_show (#312) 2023-05-31 22:08:57 +02:00
sandr01d 0bedb80c1f
Allow passing parameters to forgit::reset::head (#309) 2023-05-31 21:18:13 +02:00
Tom f73ae9754e
Allow configuration of checkout_branch branch cmd (#307) 2023-05-16 08:45:18 -07:00
Tim 5642a1a730
Use correct IFS store/restore mechanism (#306)
The previous implementation had the problem that if IFS was not set
before, it was set to an empty string after restoring, which is not the
same as being unset. This broke grc / git forgit revert_commit, since
"git revert" was being interpreted as the command name instead of
command and argument.

The correct way is to check whether IFS is unset and, if so, unset it
again afterwards.

See for reference:
https://unix.stackexchange.com/a/264947/317320
2023-05-08 09:51:13 -07:00
Tim f74aa93232
Fix grc / forgit revert_commit (#305)
This was accidentally broken since 450615d4 due to a wrong git call.
2023-05-07 11:53:19 +02:00
Tim 3f00348d5c
Add keybinding ctrl+y for copying stash ID in gss (#295) 2023-03-18 16:35:18 +01:00
Tim 2b0cf3c4af
Fix temporary IFS settings (#297)
When setting the IFS for a certain command only, the command must not be
an assignment, otherwise both assignments are evaluated permanently
(see https://unix.stackexchange.com/a/458901/317320).
2023-03-18 16:34:24 +01:00
Tim 450615d48f
Fix git options (#296)
Adding options to a command in a quoted variable as introduced in #292
causes problems in several cases unfortunately (e.g. git rebase
interpreting an empty string argument as a remote, which leads to an
error "unknown upstream ''").

Change the implementation in a way that each git command is stored in a
shell variable, including the options, which is then evaluated.
This also makes the code more DRY because each git options variable is
evaluated only once.

Furthermore, fix temporary IFS settings. When setting the IFS for a
certain command only, the command must not be an assignment, otherwise
both assignments are evaluated permanently
(see https://unix.stackexchange.com/a/458901/317320).
2023-03-18 16:18:11 +01:00
Tim 2a2ee36d56
Add git options for each forgit command (#292)
The git behavior within forgit can now be customized with a dedicated
variable for each forgit command, e.g. `FORGIT_ADD_GIT_OPTS` is passed
to the `git add` call within `ga`.

Also renaming `FORGIT_STASH_PUSH_OPTS` to `FORGIT_STASH_PUSH_FZF_OPTS`
and `FORGIT_REVERT_COMMIT_OPTS` to `FORGIT_REVERT_COMMIT_FZF_OPTS`
for consistency.
2023-03-18 12:25:20 +01:00
Tim f32fd305dc
Fix broken cherry picking (#294)
With the changes of #261 and #266 we accidentally broke the return value
of `_forgit_cherry_pick`, which led to the loop in
`_forgit_cherry_pick_from_branch` being terminated in the wrong cases.
Fix this by moving all the post processing after fzf to a later call.

Also simplify the array population using a single line instead of a
loop.

This should also fix #286 ("fatal: bad revision ''").
2023-03-18 12:19:39 +01:00
Tim 4b8234a9ff
Only show available cherry picks in preview (#293)
This is a follow-up to #266, which already switched to showing only
available commits during cherry-picking. This patch does the same for
the branch preview in _forgit_cherry_pick_from_branch.
2023-03-18 12:10:26 +01:00
Tim 8012396587
Fix empty diff preview on renames (#282)
This had been fixed before in #189, but obviously the patch broke
support for whitespaces in file names. That was fixed in #204, which
in turn broke support for renames again.

Prepare the list of file names with the null-character \0 as a delimiter,
so that we can use "xargs -0" to read it. This makes renames as well
as filenames with spaces work correctly.
2023-02-28 22:57:51 +01:00
ZenLian 8502ae2cc5
fix: glo can not match files (#249)
Fixed "glo -- <files>" behavior to show specified files only instead of
showing all changed files.
2023-01-30 17:43:17 +01:00
sandr01d c098bf2fb1
Modify multiple files at once in ga & gcf (#279)
Checkout/Add files in a single command in _forgit_add and _forgit_checkout_file() instead of processing each file individually with xargs. This has the following benefits:

    It's faster
    Prevents git from spamming "Updated 1 path from the index" for each file when checking out files
2023-01-20 11:49:55 -08:00
Chris Apple 98637db1b0
Only show available cherry picks (#266)
Only shows changes that are eligible for cherry-pick to the branch, not every commit. Also adds nice color to the output
2023-01-11 10:50:41 -08:00
Tim 548af731f0
Fix command list in help output (#274)
'rebase' and 'fixup' were accidentally displayed on the same line.
2023-01-11 10:22:53 +01:00
sandr01d 329523bd0d
Fixed: Untracked files with spaces in the path do not show a preview in 'ga' (#271) 2023-01-11 08:47:40 +01:00
Chris Apple ffda73bac3
Adding the ability to grh from a subdirectory (#262)
grh didn't work if you were in a subdirectory. See #254 for more details
2022-12-19 10:57:58 -08:00
Chris Apple 5a117b63cd
Ensure that grc and gcp always have the correct ordering, regardless of how they were input (#261) (#253)
Closes #253. Essentially the idea is this:

    When cherry picking a group of commits, most of the time you want to cherry pick oldest to newest. This means you have the lowest chance of having a conflict or error
    when reverting a commit. You most often want to revert from newest to oldest. Similarly prevents errors

This commit does that, based on the wonderful suggestion on how to do that from @carlfriedrich in the linked ticket (#253).
2022-12-16 06:50:28 -08:00
Changsheng Wu 8ca463b5c6
Do not hardcode $SHELL path for bash (#260)
Some systems do not have /bin/bash. e.g., Alpine and NixOS. This change reads
the path dynamically via `which`. It solves the error `fork/exec /bin/bash`.
2022-12-15 09:34:11 +01:00
sandr01d f8c0edfc17
Added git stash push selector 'gsp' (#251)
A message can be passed via named argument (-m or --message). All other
arguments (e.g. file paths) will cause git stash push to be run directly without
invoking fzf.
2022-12-14 15:53:52 +01:00
Chris Apple 62cc8abde1
Provide an input branch with gcp again (#252)
Noticed there was a change recently that broke the ability to pass in an input branch to gcp.

This change is the following:

    Fix faulty logic that just led to a git checkout -b being called when you pass in an argument to gcp
    If an argument was passed in, check if it is a valid branch, if so, set the input_branch var
    If input_branch is set, use it to do the cherry pick, as opposed to the first FZF selection.
2022-12-13 16:42:07 -07:00
Tim 59dd63be77
Fix forgit diff displaying renames on MacOS (#250)
MacOS's 'sed' variant obviously does not parse '\t' as a tabstop per
default. Replacing it with a literal tabstop to make this work.
2022-12-02 08:33:07 +01:00