Before forgit became a standalone script, users defined their FORGIT
variables (e.g. FORGIT_FZF_DEFAULT_OPTS) in the shell environment before
sourcing the forgit shell plugin. This worked because the forgit code
was executed within the currently running shell.
With forgit being an executable script, these variables are only
available to forgit when being exported. This patch adds an automatism
for this so that users do not have to change their configuration.
A warning is issued in this case so that users get notified to update
their configuration.
Fish stores command line arguments in $argv, which is an array. Unlike
in bash, when passing this array to a function, we must not enclose it
in double-quotes. This made an empty argument list (i.e. no arguments
passed) to an actual empty string argument (i.e. one argument passed),
which is not what we want.
See https://stackoverflow.com/a/42379014/3018229
Previously we had two different forgit implementations: one for zsh/bash
and one for fish. In this commit we move the bash implementation of the
forgit functions to the git-forgit script in order to have them in the
form of an executable script. This makes using forgit possible without
any shell plugin at all and furthermore removes the need to maintain a
separate implementation for the fish shell.
The simplest way of using forgit from now on is to put git-forgit
somewhere in your PATH and call it via "git forgit", without the need
for any other files.
We keep the shell plugins, though, and maintain backwards compatibility
by retaining the plugin functions as simple wrappers around the
git-forgit script, making the plugins mainly a collection of aliases
only.
fzf has the following exit codes:
0 Normal exit
1 No match
2 Error
130 Interrupted with CTRL-C or ESC
The forgit functions "log", "diff" and "stash show" are designed to
display information, not to perform any action. Hence the fzf exit code
130 should not be interpreted as an error, it is normal exit behavior.
Exclude this error value and return 0 in this case.
I added a bunch of "wraps" commands to our functions. This is basically a quick and easy way to get function completion for free. Users can now tab complete most commands that take an argument
When we want to perform a cherry pick, we had to pass the target branch
as an argument to gcp. Forgit, however, aims to make git selections
interactive where possible. Hence it seems natural to select the target
branch interactively as well.
Git stashes are named "stash@{x}", which contains the fzf placeholder
"{x}". In order to support passing stashes as arguments to forgit::diff,
we have to prevent fzf from interpreting this substring by escaping the
opening bracket.
The pager used on fzf enter key binding commands was hardcoded to
"LESS='-r' less". Transfer this to a variable in order to reduce code
duplication and make it configurable.
The git rebase command needs to be passed the parent commit of the one
you want to edit. When selecting a commit interactively via fzf, it
makes sense to automatically pass the parent commit of the selected one.
Within fzf it's otherwise quite hard to find the parent commit by hand
if you have found your commit via an fzf search string.
This reduces code duplication. We cannot implement this as a function,
because fish and zsh do not support exporting functions, but we need it
in subshells (see https://github.com/fish-shell/fish-shell/issues/6961).
Implement it as a variable in all shells instead.
The preview on cherry pick was accidentally broken since we included the
+/- information in the commit list. Fix this by using the correct string
index.
Git log displays the newest commits on top of the list, while git cherry
pick displays the newest commits at the bottom. Reverse the order of
git cherry pick so that it has the same order like git log.
The output of 'git cherry' which is used to build the fzf input list for
forgit::cherry::pick usually prefixes every line with a '-' for commits
that have an equivalent in the target branch, and a '+' for commits that
do not.
Previously forgit removed this information from the list. However, for
the actual cherry-picking process this information is relevant, so we
should keep it.
When using a fzf find string which maches multiple lines, the commits
could appear in a wrong order. Add "--tiebreak=index" to ensure that the
correct commit order is preserved.
The gcp (git cherry pick) command was the only command which did not
have a variable to set command-specific fzf options. Add the according
variable to source code and documentation.
* Adding support for git branch delete method in fish
* Add new doc to README
* Added options like gcb
* refactor: remove `--all` flag from gbd
* feat: sync forgit::branch::delete to bash and zsh
Co-authored-by: Wenxuan Zhang <wenxuangm@gmail.com>
Use LC_ALL=C to avoid potential ordering issues related to the user's
locale configuration. Additionally, add the --stable option to ensure
that just the range defined with --key is used.