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

Open
wants to merge 4 commits into
base: master
from

Conversation

Projects
None yet
2 participants
@micgro42
Collaborator

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
Michael Gro脽e
馃悰 make getVersion show the commit date, not checkout date
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

This comment has been minimized.

Owner

splitbrain commented Jul 5, 2018

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

This comment has been minimized.

Collaborator

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.

Michael Gro脽e added some commits Jul 5, 2018

Michael Gro脽e
馃憣 Add fallback if we cannot use git on the shell
Under some circumstances, there may be no git or no shell access available. This gets the commit
date manually.
Michael Gro脽e
$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);

This comment has been minimized.

@splitbrain

splitbrain Sep 7, 2018

Owner

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

This comment has been minimized.

@micgro42

micgro42 Sep 9, 2018

Collaborator

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.

$subDir = substr($headCommit, 0, 2);
$fileName = substr($headCommit, 2);
$gitCommitObject = DOKU_INC . ".git/objects/$subDir/$fileName";
$commit = zlib_decode(file_get_contents($gitCommitObject));

This comment has been minimized.

@splitbrain

splitbrain Sep 7, 2018

Owner

zlib may not be available, we need to return an unknown date then

馃悰 Add guard for getVersion fallback
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment