feat: overwrite git attrs with dirty status - #199
Conversation
Signed-off-by: tison <wander4096@gmail.com>
Signed-off-by: tison <wander4096@gmail.com>
|
The question is, in the mentioned usecase, where the file is locally changed, the |
|
That's correct. Do you logically want a I think we can implement it with minijinja, whether it's an upstream function or we can register one. |
| @@ -1 +1,2 @@ | |||
| Copyright {{attrs.git_file_created_year if attrs.git_file_created_year else attrs.disk_file_created_year }} No newline at end of file | |||
| Copyright {{attrs.git_file_created_year if attrs.git_file_created_year else attrs.disk_file_created_year }} | |||
| Modified {{[attrs.git_modified_year, attrs.disk_file_modified_year] | max}} No newline at end of file | |||
There was a problem hiding this comment.
If max is what you need, you can try out this example.
There was a problem hiding this comment.
There was a problem hiding this comment.
Sounds as it could work. Will try it later and give you feedback.
There was a problem hiding this comment.
Emm .. I think it may not work because all mtime locally would be the very late time after you clone the files.
So for a new cloned local copy, it would be then all "this year".
There was a problem hiding this comment.
Let me think of it. The requirement is to track all modified files by VCS, but use the mtime from the local FS.
I need some time to consider what is the proper filter and extract way.
There was a problem hiding this comment.
Perhaps patching git::resolve_file_attrs to add an attrs.git_dirty_file_modified_year, and then:
{{ attrs.git_dirty_file_modified_year if attrs.git_dirty_file_modified_year else attrs.git_file_modified_year }}
There was a problem hiding this comment.
I think that would fit. So in case the file is not changed locally, attrs.git_dirty_file_modified_year will not be set. In case it is changed locally, it will get the current year.
Signed-off-by: tison <wander4096@gmail.com>
Signed-off-by: tison <wander4096@gmail.com>
Signed-off-by: tison <wander4096@gmail.com>
|
@Lorilatschki updated. I finally chose a different approach - just override the |
| // process dirty working tree | ||
| let status_platform = repo.status(gix::progress::Discard)?; | ||
| let status_iter = status_platform.into_index_worktree_iter(None)?; | ||
| let now = gix::date::Time::now_local_or_utc(); | ||
| for item in status_iter { | ||
| let item = item.context("failed to check git status item")?; | ||
| let rel_path = item.rela_path(); | ||
| update_attrs(rel_path, now, current_username.as_str()); | ||
| } |
There was a problem hiding this comment.
TIL for implementing #199 (comment).
cc @Byron in case this is not the best practice.
There was a problem hiding this comment.
There also is status_platform.into_iter() (or something more general) to get the changes that were added to .git/index as well. The current version doesn't get all changes git status would show.
Otherwise this would be the way the paths of changed items.
There was a problem hiding this comment.
Thanks for your explaination!
I can see the alternative method returns an extra TreeIndex result. But I'm always using linear commit history, so I'm not quite familiar with the difference. Is there some reference I can use to understand what those extra indices are?
There was a problem hiding this comment.
I don't follow, but think that something like this would do the trick: https://github.com/GitoxideLabs/gitoxide/blob/657dec4f10bc6babbfa71a4506b1ff1439c06eaf/gix/tests/gix/status.rs#L213-L241
There was a problem hiding this comment.
Thanks! IIUC it means into_iter would properly include those file changed after git add . while into_index_worktree_iter only includes those files changed but yet to be added (in the working tree, not in the index).
| let current_username = match repo.committer() { | ||
| Some(Ok(username)) => username.name.to_string(), | ||
| _ => "<unknown>".to_string(), | ||
| }; |
There was a problem hiding this comment.
cc @Byron ditto preparing the "default author" for dirty changes.
There was a problem hiding this comment.
You can do it like this and it's probably easiest as well, as long as you don't find yourself duplicating the logic to deal with an unset committer. In that case, fallbacks for missing committers can be set upon opening the Gix repository.
|
So if I understand it correctly, this will fix the behavior without any adaption on our site except the new version which contains this change, right? |
Yes. You can test it with cargo install --path path-to-hawkeye for testing locally. |
Will test it locally and give you feedback if it works. In any case, we should add a test to verify that the 2 attributes behave as expected in case the are change locally. |
|
Have tested both scenarios with the local installation of your branch
|
|
Thank you. I tested it locally as well. I'm going to refactor the integration tests with trycmd instead of Python script then add more test cases. |
This closes #197.
cc @Lorilatschki
Then you should be able to use: