mirror of
https://github.com/oh-my-fish/oh-my-fish.git
synced 2025-02-06 21:44:00 +08:00
Check whether we are inside the worktree (#651)
Some git commands require to be run from inside the worktree (as opposed to the git dir, although it's usually in .git). This commit adds a function git_is_worktree to check this. It is used for the commands that need the worktree instead of git_is_repo. An alternative solution might have been to find the git worktree in the parent of the git directory, but this doesn't work for all cases. Generally it's impossible to detect the location of the worktree (plus it's not unique). Co-authored-by: Pablo Aguiar <scorphus@gmail.com>
This commit is contained in:
parent
e7a8e74f19
commit
b1b10c333d
|
@ -1,3 +1,3 @@
|
|||
function git_is_dirty -d "Check if there are changes to tracked files"
|
||||
git_is_repo; and not command git diff --no-ext-diff --quiet --exit-code
|
||||
git_is_worktree; and not command git diff --no-ext-diff --quiet --exit-code
|
||||
end
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
function git_is_touched -d "Check if repo has any changes"
|
||||
git_is_repo; and begin
|
||||
git_is_worktree; and begin
|
||||
# The first checks for staged changes, the second for unstaged ones.
|
||||
# We put them in this order because checking staged changes is *fast*.
|
||||
not command git diff-index --cached --quiet HEAD -- >/dev/null 2>&1
|
||||
|
|
4
lib/git/git_is_worktree.fish
Normal file
4
lib/git/git_is_worktree.fish
Normal file
|
@ -0,0 +1,4 @@
|
|||
function git_is_worktree -d "Check if directory is inside the worktree of a repository"
|
||||
git_is_repo
|
||||
and test (command git rev-parse --is-inside-git-dir) = false
|
||||
end
|
|
@ -1,5 +1,5 @@
|
|||
function git_untracked -d "Print list of untracked files"
|
||||
git_is_repo; and begin
|
||||
git_is_worktree; and begin
|
||||
command git ls-files --other --exclude-standard
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue
Block a user