Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make dirty state better #54

Closed
wants to merge 1 commit into from

Conversation

zzhaolei
Copy link

@zzhaolei zzhaolei commented Apr 22, 2024

Current dirty status may be incorrect, use better detection method

Incorrect, Nothing actually changes:
image

Correct:
image

Performance:
No performance regression.

(Can it be tested like this?🤔)
image

@zzhaolei
Copy link
Author

@jorgebucaran Please review this PR

@jorgebucaran
Copy link
Owner

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.

@zzhaolei
Copy link
Author

Hello, I have been using it for three weeks and haven't noticed any problems. Can it be merged?

@jorgebucaran
Copy link
Owner

Good to know, thanks!

@zzhaolei
Copy link
Author

zzhaolei commented May 16, 2024

Now we can use this:

Old ``` count (git status --porcelain=v2 --untracked-files=no) >/dev/null; or count (command git ls-files --others --exclude-standard) >/dev/null; and set info \"$hydro_symbol_git_dirty\" ```

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 outputstime 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 outputstime 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 outputstime 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 zzhaolei force-pushed the better-dirty-state branch 2 times, most recently from 1170524 to 65f1302 Compare May 17, 2024 09:32
@zzhaolei
Copy link
Author

🙋

@zzhaolei zzhaolei changed the title fix: better dirty state make dirty state better Sep 27, 2024
@jorgebucaran
Copy link
Owner

@zzhaolei What is make gen-api?

@zzhaolei
Copy link
Author

This is goctl api go --api=xx.api --dir=., which means to regenerate the file.

docs: goctl api, demo

@zzhaolei
Copy link
Author

zzhaolei commented Oct 20, 2024

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 ➜

@jorgebucaran
Copy link
Owner

Why's setting the modification time relevant here? Why not just touch a new file?

@zzhaolei
Copy link
Author

This is the behavior of goctl generating files. I will not actively modify the time.

@zzhaolei
Copy link
Author

Now thinking about it, this is a weird behavior and changing it doesn't make much sense.

I will close this PR.

@zzhaolei zzhaolei closed this Oct 20, 2024
jorgebucaran added a commit that referenced this pull request Oct 20, 2024
Use `git rev-parse --show-toplevel` to ensure correct path in subdirs

See #54
@jorgebucaran
Copy link
Owner

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.

@zzhaolei
Copy link
Author

zzhaolei commented Oct 21, 2024

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 ➜

@zzhaolei
Copy link
Author

zzhaolei commented Oct 21, 2024

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 ➜

@jorgebucaran
Copy link
Owner

Was wondering what would happen if there were spaces in the user's path.

@zzhaolei
Copy link
Author

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 ➜

@jorgebucaran
Copy link
Owner

I dropped the ball. My bad. Will push a fix shortly.

@zzhaolei zzhaolei deleted the better-dirty-state branch October 21, 2024 13:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants