Commit graph

123 commits

Author SHA1 Message Date
carlfriedrich 77ce6db8b4 feat: resolve a relative FORGIT_WORKTREE_ADD_DIR per repository
A relative FORGIT_WORKTREE_ADD_DIR is resolved against the root of the
main worktree on every invocation, so a single setting such as
`.worktrees` is valid in every repository. Absolute paths keep their
meaning.

The variable previously only took a full path, so users resolved the
repository root in their shell startup files, which runs git outside a
repository on every new shell and freezes the path for the whole
session.
2026-09-09 20:19:47 +08:00
sandroid 0fbd9edd87
feat: add option to disable auto creating branches (#552)
Some checks failed
ci / build (macos-latest) (push) Has been cancelled
ci / build (ubuntu-latest) (push) Has been cancelled
ci / commitlint (push) Has been cancelled
ci / format (push) Has been cancelled
ci / rumdl-check (push) Has been cancelled
ci / actionlint (push) Has been cancelled
Adds `$FORGIT_SWITCH_AUTO_CREATE_BRANCH` and `$FORGIT_CHECKOUT_BRANCH_AUTO_CREATE_BRANCH`
environment variables that can be set to `false` to prevent `checkout_branch <BRANCH_NAME>` and
`switch_brach <BRANCH_NAME>` from creating new branches when they do not exist. With the environment
variables set to `false`, new branches can still be created explicitly using
`switch_branch -c <BRANCH_NAME>` and `<checkout_branch> -c <BRANCH_NAME>` respectively.
2026-09-02 00:58:17 +02:00
Wenxuan Zhang 2420155e23 fix: preserve LESS options in enter pager
Some checks are pending
ci / build (macos-latest) (push) Waiting to run
ci / build (ubuntu-latest) (push) Waiting to run
ci / commitlint (push) Waiting to run
ci / format (push) Waiting to run
ci / rumdl-check (push) Waiting to run
ci / actionlint (push) Waiting to run
Pass the required color and stay-open flags directly to less so forgit no longer
replaces users' LESS environment options.

Add regression coverage and document the default behavior.
2026-08-25 13:57:48 +08:00
Chris Apple 15db001662
perf: avoid listing modified files twice in checkout-file (#546)
_forgit_checkout_file called _forgit_list_modified_files once to check for
an empty result and again to feed fzf, running git diff twice on every
invocation. Cache the result and reuse it for both checks.
2026-07-15 15:06:19 -07:00
Chris Apple a8e9d8bf57
perf: speed up modified file lookup in large repositories (#544)
Use a modified-file-only path for `git-forgit restore` (`grs`) and
`git-forgit checkout_file` (`gcf`) so these interactive selectors do not scan
large sets of untracked files. This keeps both commands responsive in
repositories with many untracked files.
2026-07-13 10:05:53 -07:00
carlfriedrich efa8c39b0d fix: support arbitrary whitespace in _forgit_parse_array
Values spanning multiple lines (e.g. a multi-line FORGIT_*_GIT_OPTS
export) were silently dropped: read stopped at the first newline and
IFS only split on spaces, so the resulting array came out empty.

Split on spaces, tabs and newlines and consume the whole value with an
empty delimiter, ignoring leading/trailing whitespace.

Add unit tests covering space-, tab- and newline-separated inputs.
2026-06-28 14:04:02 +02:00
sandroid 3dbcacd3f2
feat: add interactive git restore selector (#537)
Co-authored-by: Javier Tia <floss@jetm.me>
2026-06-16 21:16:26 +02:00
sandroid 0eebd5ed1e
fix: fix typo (#520) 2026-04-19 00:04:39 +02:00
sandr01d dfe682e113
ci: enforce consistent shell formatting with shfmt (#514) 2026-04-11 17:51:34 +02:00
sandroid 7663f3a809 fix: branch preview of worktree_add 2026-04-09 21:34:56 +02:00
sandroid 0353f58b0b fix: log preview of checkout_file_from_commit 2026-04-09 21:34:56 +02:00
Wenxuan 17110bfc61
fix: preserve add paths across special filenames (#506)
Keep `forgit add` on the porcelain `git status --porcelain -zs` path so
filenames containing backslashes continue to work, while restoring the
behaviors that regressed when we moved away from Git's cwd-relative output.

This change makes the status picker emit a display label and a hidden
absolute-path payload separately. That lets the UI keep showing intuitive
cwd-relative paths, while preview, edit, and add actions operate on the real
path instead of reparsing the rendered status line. As a result, untracked
files, subdirectory workflows, and special filenames now share one consistent
path flow.

It also restores the old-Git fallback for plain `?? path` output before status
filtering, raises the required fzf version for `--accept-nth`, and adds
regression coverage for backslashes, spaces, tabs, subdirectory entries,
sibling directories, and logical symlink paths.

We explored a few alternatives before landing here. Keeping a single
human-readable line and reparsing it downstream remained too fragile for
quoted paths and backslashes. Shell-only display-path rewriting worked for
some cases but stayed brittle across logical vs physical paths and still
failed in macOS CI. A per-path `realpath` approach would have been easier to
read, but GNU-style relative-path support is not portable across the
platforms we test and would add one external process per file in a hot path.

The final tradeoff keeps the pipeline batch-oriented and portable by doing
the path normalization once in a single helper step, even though that is less
lightweight than the earlier shell-only versions. That complexity is
justified here because it fixes the old-Git untracked regression, preserves
correct preview/add behavior from subdirectories, and avoids reintroducing
long-standing filename parsing bugs.
2026-04-08 10:40:03 +08:00
sandroid 2c17635d4f fix: handle backslashes in filenames in _forgit_worktree_changes
Git escapes backslashes with `git status` even when
`core.quotepath=false` is set. Use `--porcelain -z` with `git status` as
a more robust approach to fix this.

Fixes #467
2026-03-17 17:22:32 +01:00
sandroid 1bc93a2c3a refactor: extract _forgit_worktree_changes from _forgit_add 2026-03-17 17:22:32 +01:00
sandroid 12ec178093 feat: add interactive checkout file from commit selector
closes #476
2026-03-17 17:21:28 +01:00
sandroid b82812007c refactor: extract _forgit_git_show from _forgit_show 2026-03-17 17:21:28 +01:00
sandroid 41912c2907 refactor: extract _forgit_git_log from _forgit_log 2026-03-17 17:21:28 +01:00
sandr01d 30aff90e30
refactor: remove command specific previews from PRIVATE_COMMANDS (#501)
These are no longer necessary due to the new `preview` function
2026-03-17 09:33:24 +08:00
Wenxuan f7e2d436de
fix: use non-interactive pager in fzf preview for TUI pagers (#498)
When users configure a TUI/interactive diff pager (e.g., diffnav, tig)
via `git config pager.diff`, fzf preview panes show blank output because
TUI pagers require a TTY that fzf previews don't provide.

Add FORGIT_PREVIEW_PAGER env var that overrides the diff pager only in
fzf preview context. Preview detection relies on a FORGIT_IN_PREVIEW
marker set by a new `_forgit_preview` wrapper, so the override applies
only to preview commands and leaves fullscreen behavior unchanged.

Fixes #491
2026-03-14 10:38:44 +08:00
Wenxuan Zhang 7f9ea3a4b1 feat: add interactive worktree add command (gwa)
Add `gwa` command for interactively creating git worktrees with
fzf-powered branch selection.

Usage:
- `gwa`: select a branch to create a worktree for
- `gwa <new-branch>`: create a new branch from a selected base branch
- 2+ args: fall back to `git worktree add` directly

New worktrees are created under `$FORGIT_WORKTREE_ADD_DIR` (defaults to
`<repo-root>/.wt/`) and the shell automatically cd's into the result.
2026-03-12 10:07:34 +08:00
Wenxuan Zhang de5406cdda fix: use array length instead of string length in reset_head
`${#files}` checks the string length of the first element, not the
array length. Use `${#files[@]}` to correctly detect an empty array.
2026-03-10 09:21:22 +08:00
Wenxuan Zhang 3b9ebce8bc refactor: extract _forgit_print_dim helper and improve worktree ops
- Extract dim formatting into _forgit_print_dim() to replace hardcoded
  ANSI sequences in _forgit_branch_list()
- Add empty state check and alt-l lock toggle reload for worktree delete
- Fix worktree path completion to handle paths with spaces using -z flag
- Add worktree command completion for bash and zsh
2026-03-10 09:20:16 +08:00
Wenxuan Zhang fc081846c0 feat: add interactive git worktree operations
Add worktree browser (gwt) and worktree delete selector (gwd) with:
- Interactive worktree list with lock status, branch info, and age
- Preview showing working tree status and recent commits
- Ctrl-Y to copy worktree path, Alt-L to toggle lock/unlock
- Shell integration for zsh (with cd) and fish (with cd)
- Tab completions for zsh, bash, and fish
- Documentation in README with keybindings and options

Co-Authored-By: Sufien Tout <sufientout@gmail.com>
2026-03-10 09:20:16 +08:00
Wenxuan Zhang ea58599e66 refactor: extract branch helpers and ANSI strip utility
- Add _forgit_strip_ansi for removing ANSI escape codes
- Add _forgit_branch_list to list branches with current branch first
- Add _forgit_extract_branch_name to parse branch names from git output
- Update checkout_branch, switch_branch, branch_delete, cherry_pick_from_branch,
  and branch_preview to use the new helpers
- Fix _forgit_inside_work_tree to suppress stderr
2026-03-10 09:20:16 +08:00
sandr01d 151d61daff
fix: forgit add shows dir view for submodules (#484) 2025-12-21 20:45:56 +01:00
Jose M. Valera Reales 76506fc3da
Feature: add empty state messages for checkout commands (#478)
Show informative messages when there is nothing to checkout:
  - checkout_file: "Nothing to checkout." when no modified files
  - checkout_tag: "Nothing to checkout: there are no tags."
2025-12-10 20:23:14 +01:00
Iván Sotillo del Horno 3cd63a1bbe
Feature: add interactive git switch selector (#472) 2025-12-10 20:19:26 +01:00
sandr01d 779b59690f
Feature: allow configuring arguments of git ls-files in forgit clean (#481) 2025-12-08 20:24:11 +01:00
sandr01d b9ed7bc40e
Fix: preview for clean when file names contain backslashes (#465)
This is a breaking change: flag arguments provided to forgit clean are
now passed to git ls-files instead of git clean -n. This change is
necessary because git clean does not have a -z option that would prevent
it from escaping file names containing backslashes. However, git ls-files
is way more flexible than git clean, so all use cases covered by git
clean (and more) should still be possible.
2025-12-05 22:58:46 +01:00
carlfriedrich 2a4e2e53b7 Refactor: extract function to remove status from diff line (#464) 2025-09-08 06:47:52 +02:00
carlfriedrich ab6a63ee0f Chore: Do not execute any code when forgit is sourced (#464)
In order to run unit tests for individual functions we have to be able
to source the script without triggering the main execution flow.
2025-09-08 06:47:52 +02:00
carlfriedrich 9b3b185e24 Refactor: Move global code into a main function (#464)
This is a prequisite for being able to source the script in order to
implement unit tests for individual functions.
2025-09-08 06:47:52 +02:00
sandr01d f7796d5ce2
Fix: use github/gitignore for ignore files (#461)
The repo we originally used has gone away
2025-07-30 19:19:33 +02:00
sandroid 9a4ff16829 Fix: files in untracked directories are not shown in git add
Pass the value of git config status.showUntrackedFiles to the git status
command we run in _forgit_add, defaulting to 'all' when unset.
Additionally correctly handle directories in _forgit_add_preview for the
case when status.showUntracked is explicitly set to 'normal'.
2025-07-23 09:39:37 +02:00
sandr01d 8285d2e1b0
Fix: early out with non-file arguments in checkout file (#456) 2025-07-16 20:37:06 +02:00
sandr01d fd373ba6c2
Fix: remove explicit -u flag in git status command in _forgit_add (#455)
git status includes untracked files by default, so passing the flag
explicitly is not necessary. This allows overriding forgits behavior
by setting showUntrackedFiles = no in the .gitconfig.
2025-07-15 21:00:04 +02:00
carlfriedrich c0df9a56d0 Refactor: Remove unnecessary xargs in git show commands 2025-07-15 06:36:45 +02:00
carlfriedrich cfc954ebc0 Feat: Use forgit show in stash_show enter (#450)
Instead of using `git stash show` in the `enter` binding of the
`stash_show` command, use `forgit show`. This allows forgit to show the
stash in the same interactive way it shows other commits (e.g. on
`forgit log`), with the same context and formatting options.
2025-07-15 06:36:45 +02:00
sandr01d b71e54c4aa
Feate: allow passing arguments to git checkout file (#451) 2025-07-13 15:41:48 +02:00
sandr01d fe350db899
Feat: allow passing arguments to git add (#452) 2025-07-13 15:41:14 +02:00
sandr01d 7a5e68b11b
Fix: allow filtering by files in fixup, squash and reword (#448)
This reverts commit 3f694f6e99 and adds the same filtering option to reword.
2025-06-21 00:36:27 +02:00
sandroid d477ffaee4 Refactor: do not disable shellcheck 2230
It is optional with ubuntu 24.04 and disabled by default.
2025-06-03 09:37:29 +08:00
sandr01d 455e42ba64
Feature: add interactive reword selector (#443) 2025-05-29 20:51:12 +02:00
sandr01d 3f694f6e99
Refactor: Do not pass files to fixup and squash (#442)
Similar to 09f17c9, this removes the option to pass files to the fixup
and squash functions. There is no need to do so.
2025-05-28 19:37:36 +02:00
sandr01d c2b012855f
Feature: add interactive squash selector (#440) 2025-05-25 18:21:56 +02:00
sandr01d 47fd184c7c
Fix: use FORGIT_SHOW_FZF_OPTS in _forgit_show (#437) 2025-05-05 18:16:52 +02:00
sandr01d 79c4e5a4c4
Fix: create branch when checking non origin remote (#430) 2025-04-22 18:08:37 +02:00
carlfriedrich 09f17c9032
Allow passing arguments to git rebase (#422)
Some checks failed
ci / build (ubuntu-22.04) (push) Failing after 1s
ci / build (macos-latest) (push) Has been cancelled
ci / build (ubuntu-20.04) (push) Has been cancelled
If non-option arguments are passed to `git forgit rebase`, pass them
through directly to `git rebase`, without launching the interactive
selector, just like we do for other forgit commands.

Along with this, remove possibility to pass files to rebase, as there is
no need for that. I assume this was a copy-paste error when the
rebase function was introduced in the first place.
2025-02-15 14:57:57 +01:00
sandroid 0d65efc769 Feature: Add interactive git attributes generator
Some checks failed
ci / build (macos-latest) (push) Waiting to run
ci / build (ubuntu-20.04) (push) Waiting to run
ci / build (ubuntu-22.04) (push) Failing after 1s
2025-02-14 20:29:33 +01:00
sandroid 408fe6033a Refactor: Make functions interacting with repositories reusable 2025-02-14 20:29:33 +01:00