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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悰 make getVersion() show the commit date, not checkout date #2443

Merged
merged 4 commits into from Oct 13, 2020

Conversation

micgro42
Copy link
Collaborator

@micgro42 micgro42 commented Jul 5, 2018

Currently, getVersion() shows the date when the HEAD of the local git repository was last changed, not the date of the current commit. This pull request fixes that behavior.

Steps to reproduce:

  1. checkout an old DokuWiki commit - say from a month or a year ago
  2. go to the admin screen
  3. look at the version:
    • without this pull request it will show the date of today
    • with this pull request it will show the date of the commit

Currently, getVersion() shows the date when the HEAD of the local git
repository was last changed, not the date of the current commit. This
commit fixes that behavior.
@splitbrain
Copy link
Collaborator

This requires to have git installed and executable by the webserver user which may not always be the case. I wonder how often it happens that someone is running a commit that's not the head.

@micgro42
Copy link
Collaborator Author

micgro42 commented Jul 5, 2018

No, this is not how it works.

If I make a git pull today and get the current tip of the master branch and you make a git pull tomorrow and get the same commit, then getVersion() will report two different dates for us. It currently acts more as a getLastUpdate() when it comes to git commits, while it should always show the same output for the same commit.

I will look into making it work without access to the shell.

Under some circumstances, there may be no git or no shell access available. This gets the commit
date manually.
$date = date('Y-m-d',array_pop($chunk));
if($date) $version['date'] = $date;
if ($date = shell_exec("git log -1 --pretty=format:'%cd' --date=short")) {
$version['date'] = hsc($date);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we skip the shell access completely and always do it manually?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, because manual may not reliably work either. Git tends to pack objects to save space locally and I'm not sure how to get that specific commit out of such a pack without git itself.

inc/infoutils.php Outdated Show resolved Hide resolved
This protects against the current commit being packed and not available
 as an object and against zlib not being available.

More information about commits being packed and thus not available can
be found here: https://git-scm.com/book/en/v2/Git-Internals-Packfiles
@Klap-in
Copy link
Collaborator

Klap-in commented Oct 12, 2020

Is this PR now fine?

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.

None yet

3 participants