Commit graph

114 commits

Author SHA1 Message Date
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
sandr01d e07b353b94
Refactor: Remove _forgit_ignore_clean (#421)
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
2025-02-10 19:36:13 +01:00
carlfriedrich bb83b3cba0
Feature: add forgit show command (#417)
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
Introducing `show` as a new subcommand of `forgit`, an interactive
version of `git show`. The configured default alias is `gso`.

Alt-T can be used to toggle between showing the diff and the commit
message in the fzf preview window.

The new command in used instead of `forgit diff` when pressing enter
in `forgit log`. This fixes the display of diffs for merge commits.

**Note**: we have a requirement for the `fzf` version now. The minimum
required `fzf` version is 0.49.0. If the installed version is lower,
forgit will exit with an error message.

Fixes #416.
2025-01-29 07:04:07 +01:00
Wenxuan df5191157f
fix: fix edit file key binding (alt-e) in diff and add (#415)
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
The key binding for editing a file in diff and add was not working
properly on recent versions of fzf. As its documentation suggests, we
should replace `execute-silent` with `execute` since we need to switch
to a new screen and handle both input and output.

> fzf switches to the alternate screen when executing a command.
> However, if the command is expected to complete quickly, and you are
> not interested in its output, you might want to use execute-silent
> instead, which silently executes the command without the switching.
2024-12-22 09:18:39 +08:00
Sufien Tout 7a40a11e79
Meta: add an .editorconfig and apply it to the codebase (#404)
Some checks failed
ci / build (ubuntu-22.04) (push) Failing after 0s
ci / build (macos-latest) (push) Has been cancelled
ci / build (ubuntu-20.04) (push) Has been cancelled
2024-11-06 10:10:27 +01:00
sandr01d be82c47ceb
Feature: Add interactive git reflog (#398)
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
2024-09-04 22:02:27 +02:00
Wenxuan 8b60a899f4
refactor: remove -u option from git status in forgit add (#397)
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
Signed-off-by: Wenxuan Zhang <wenxuangm@gmail.com>
2024-08-15 10:06:11 +08:00
sandr01d 17394d1056
Fix special characters in file names (#388)
Git escapes special characters in it's output when core.quotePath is
true or unset. Git always expects unquoted file paths as input. This
leads to issues when we consume output from git and use it to build
input for other git commands. This commit ensures we always feed unqoted
paths to git commands.
The _forgit_list_files function is introduced to handle usage of git
ls-files with the -z flag, which ensures unquoted paths.
It replaces the direct calls to git ls-files in _forgit_reset_head,
_forgit_stash_push and _forgit_checkout_file.
In _git_reset_head the -z option is added to the git diff command to
ensure unqoted paths.
Since git clean does not support the -z flag, we disable core.quotePath
by passing a configuration parameter in _forgit_clean. The same is done for
_forgit_add.
2024-05-12 02:00:08 +02:00
sandr01d b35b309ce5
Fix: Opening files from diff line when not in project root (#393)
When trying to open a file from gd in $EDITOR (alt + e) the wrong file
was being opened when the command wasn't executed from the repository's
root directory.
2024-04-27 16:42:37 +08:00
sandr01d 6f212fd2b2
Fix: gsp does not work outside the root directory (#386) 2024-04-26 23:03:42 +02:00