Closed zzhaolei closed 3 weeks ago
@jorgebucaran Please review this PR
This is probably good. I also had a couple of weird issues with the dirty status. Thank you! I just need to test it on the wild for a while before we're able to merge.
Hello, I have been using it for three weeks and haven't noticed any problems. Can it be merged?
Good to know, thanks!
Now we can use this:
Edited: Now we can use this:
count (git status --porcelain=v2 --untracked-files=no) >/dev/null;
or count (command git ls-files --others --exclude-standard \$(command git rev-parse --show-toplevel)) >/dev/null;
and set info \"$hydro_symbol_git_dirty\"
# Incorrect outputs
❯ time command git ls-files --others --exclude-standard [17:37:03]
________________________________________________________
Executed in 28.84 millis fish external
usr time 16.23 millis 0.09 millis 16.14 millis
sys time 10.42 millis 1.08 millis 9.33 millis
# Correct outputs
❯ time command git ls-files --others --exclude-standard .. [17:37:05]
../1
________________________________________________________
Executed in 941.38 millis fish external
usr time 202.08 millis 0.11 millis 201.97 millis
sys time 777.69 millis 1.10 millis 776.59 millis
# Correct outputs
❯ time command git ls-files --others --exclude-standard $(command git rev-parse --show-toplevel) [17:37:10]
../1
________________________________________________________
Executed in 930.11 millis fish external
usr time 198.21 millis 0.12 millis 198.09 millis
sys time 769.98 millis 1.20 millis 768.78 millis
~/R/nixpkgs/lib master• >
🙋
@zzhaolei What is make gen-api?
Another way to reproduce:
at 11:41:09 ❯ eza -al
drwxr-xr-x@ - zhaolei 56 seconds .git
.rw-r--r--@ 0 zhaolei 1 minute 1
at 11:41:13 ❯ stat -x 1
File: "1"
Size: 0 FileType: Regular File
Mode: (0644/-rw-r--r--) Uid: ( 501/ zhaolei) Gid: ( 20/ staff)
Device: 1,16 Inode: 49251974 Links: 1
Access: Sun Oct 20 11:38:45 2024
Modify: Sun Oct 20 11:40:00 2024
Change: Sun Oct 20 11:40:11 2024
Birth: Sun Oct 20 11:38:45 2024
at 11:41:22 ❯ touch -mt 202410201141 1
~/D/T/tmp main• ➜ # <--------------------- this
at 11:42:23 ❯ git status # <------------- but worktree is clear
位于分支 main
无文件要提交,干净的工作区
~/D/T/tmp main ➜
Why's setting the modification time relevant here? Why not just touch a new file?
This is the behavior of goctl generating files. I will not actively modify the time.
Now thinking about it, this is a weird behavior and changing it doesn't make much sense.
I will close this PR.
Thanks for the idea, @zzhaolei. I just went ahead and added git rev-parse --show-toplevel
to make sure git ls-files
runs from the repo root. Should work a bit more reliably now.
git rev-parse --show-toplevel
This is not right. I have installed jorgebucaran/hydro
, but status wrong(in add files case).
new:
~/D/R/nixpkgs master ➜ git status
On branch master
Your branch is up to date with 'origin/master'.
nothing to commit, working tree clean
~/D/R/nixpkgs master 1.3s ➜ touch test
~/D/R/nixpkgs master ➜ git status
On branch master
Your branch is up to date with 'origin/master'.
Untracked files:
(use "git add <file>..." to include in what will be committed)
test
nothing added to commit but untracked files present (use "git add" to track)
~/D/R/nixpkgs master 1.1s ➜ ! command git diff-index --quiet HEAD 2>/dev/null ||
count (command git ls-files --others --exclude-standard "(command git rev-parse --show-toplevel)") >/dev/null && echo 'dirty'
~/D/R/nixpkgs master | 1 ➜
old:
~/D/R/nixpkgs master ➜ git status
On branch master
Your branch is up to date with 'origin/master'.
nothing to commit, working tree clean
~/D/R/nixpkgs master 1.3s ➜ touch test
~/D/R/nixpkgs master ➜ git status
On branch master
Your branch is up to date with 'origin/master'.
Untracked files:
(use "git add <file>..." to include in what will be committed)
test
nothing added to commit but untracked files present (use "git add" to track)
~/D/R/nixpkgs master | 1 ➜ ! command git diff-index --quiet HEAD 2>/dev/null ||
count (command git ls-files --others --exclude-standard) >/dev/null && echo 'dirty'
dirty
~/D/R/nixpkgs master 1.4s ➜
We can use it like this, removing the quotes:
! command git diff-index --quiet HEAD 2>/dev/null ||
count (command git ls-files --others --exclude-standard (command git rev-parse --show-toplevel)) >/dev/null && echo 'dirty'
Here is the complete test:
~/D/R/nixpkgs master ➜ git status
On branch master
Your branch is up to date with 'origin/master'.
nothing to commit, working tree clean
~/D/R/nixpkgs master 1.3s ➜ touch test
~/D/R/nixpkgs master ➜ git status
On branch master
Your branch is up to date with 'origin/master'.
Untracked files:
(use "git add <file>..." to include in what will be committed)
test
nothing added to commit but untracked files present (use "git add" to track)
~/D/R/nixpkgs master 1.1s ➜ ! command git diff-index --quiet HEAD 2>/dev/null ||
count (command git ls-files --others --exclude-standard (command git rev-parse --show-toplevel)) >/dev/null && echo 'dirty'
dirty
~/D/R/nixpkgs master 1.3s ➜ rm test
~/D/R/nixpkgs master ➜ git status
On branch master
Your branch is up to date with 'origin/master'.
nothing to commit, working tree clean
~/D/R/nixpkgs master 1.1s ➜ ! command git diff-index --quiet HEAD 2>/dev/null ||
count (command git ls-files --others --exclude-standard (command git rev-parse --show-toplevel)) >/dev/null && echo 'dirty'
~/D/R/nixpkgs master 1.2s | 1 ➜ nvim README.md
~/D/R/nixpkgs master• 3.3s ➜ ! command git diff-index --quiet HEAD 2>/dev/null ||
count (command git ls-files --others --exclude-standard (command git rev-parse --show-toplevel)) >/dev/null && echo 'dirty'
dirty
~/D/R/nixpkgs master• ➜ git status
On branch master
Your branch is up to date with 'origin/master'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: README.md
no changes added to commit (use "git add" and/or "git commit -a")
~/D/R/nixpkgs master• 1.3s ➜ git restore README.md
~/D/R/nixpkgs master ➜ ! command git diff-index --quiet HEAD 2>/dev/null ||
count (command git ls-files --others --exclude-standard (command git rev-parse --show-toplevel)) >/dev/null && echo 'dirty'
~/D/R/nixpkgs master 1.2s | 1 ➜
Was wondering what would happen if there were spaces in the user's path.
Everything is ok
~/test dir/t dir main ➜ pwd
/Users/zhaolei/test dir/t dir
~/test dir/t dir main ➜ git status
On branch main
nothing to commit, working tree clean
~/test dir/t dir main ➜ touch 1
~/test dir/t dir main ➜ ! command git diff-index --quiet HEAD 2>/dev/null ||
count (command git ls-files --others --exclude-standard (command git rev-parse --show-toplevel)) >/dev/null && echo 'dirty'
dirty
~/test dir/t dir main ➜ git status
On branch main
Untracked files:
(use "git add <file>..." to include in what will be committed)
./
nothing added to commit but untracked files present (use "git add" to track)
~/test dir/t dir main ➜ git rev-parse --show-toplevel
/Users/zhaolei/test dir
~/test dir/t dir main ➜
I dropped the ball. My bad. Will push a fix shortly.
Current dirty status may be incorrect, use better detection method
Incorrect, Nothing actually changes:
Correct:
Performance: No performance regression.
(Can it be tested like this?🤔)