MestreLion / git-tools

Assorted git tools, including git-restore-mtime
GNU General Public License v3.0
295 stars 74 forks source link

Timestamps just default to whatever last commit time (regardless of the files changed in that commit) #75

Closed ghnp5 closed 6 months ago

ghnp5 commented 6 months ago

Hi,

I'm running this:

git init
git config core.sparseCheckout true
git sparse-checkout set 'dir1/' 'dir2/'
git remote add origin https://${{ inputs.token }}@myowndomain.com/gitea/organization/${{ inputs.repository }}.git
git fetch --depth=1 origin master
git checkout master

And then another step where I do:

git fetch --prune --no-recurse-submodules origin +refs/heads/*:refs/remotes/origin/* +refs/tags/*:refs/tags/*

chmod +x $GITHUB_ACTION_PATH/git-restore-mtime

$GITHUB_ACTION_PATH/git-restore-mtime -v

(I tried with and without the git fetch command in the second block above)

The problem is that git-restore-mtime basically just puts the timestamp of the last commit on that repository, regardless of the file.

Any ideas what I'm doing wrong? :)

Thank you very much!

MestreLion commented 6 months ago

No idea, but settings like sparse-checkout and all the git fetch dance might trick git-restore-mtime, specially git fetch --depth=1, as IIRC it might make only the last commit to be available to git-restore-mtime, so from its point of view it's possible that it thinks all files were created in that last (and only) commit.

Care to post the execution log from --verbose? Also, is this a public repository? Care to share the URL (or a public mirror) so I can test it too? If not, what does git whatchanged --pretty=%at says, both with and without the custom fetches?

ghnp5 commented 6 months ago

Thank you for your reply.

Thanks! What you said resolved my problem, actually.

All I had to do is add --unshallow to the git fetch command before calling git-restore-mtime:

git fetch --unshallow --prune --no-recurse-submodules origin +refs/heads/*:refs/remotes/origin/* +refs/tags/*:refs/tags/*

chmod +x $GITHUB_ACTION_PATH/git-restore-mtime

$GITHUB_ACTION_PATH/git-restore-mtime -v

Appreciated!!

Thanks for the tool, and congratulations in getting it added to the distro repositories 💪🏻👍🏻 Have a great day.