Skip to content

Commit

Permalink
Fix last updated time misleading, only show when file content change
Browse files Browse the repository at this point in the history
or otherwise when it is first created

Fix #1015
  • Loading branch information
fiennyangeln committed Oct 8, 2018
1 parent 2e96569 commit f736f9c
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions v1/lib/core/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,26 @@ function idx(target, keyPaths) {
}

function getGitLastUpdated(filepath) {
const timeSpan = spawn
.sync('git', ['log', '-1', '--format=%ct', filepath])
.stdout.toString('utf-8');
// To differentiate between content change and file renaming / moving, use --summary
// To follow the file history until before it is moved (when we create new version), use
// --follow
let result = spawn
.sync('git', ['log', '--follow', '--summary', '--format=%ct', filepath]);

// Format the log results to be ['1234567', 'rename ...', '1234566', 'move ...', '1234565', '1234564']
const records = result.stdout.toString('utf-8')
.replace(/\n\s*\n/g, '\n')
.split('\n')
.filter(String);

let timeSpan = records.find((item, index, arr) => {
// The correct timeSpan will be a number which is not followed by summary meaning
// the next element is also a number OR it is the last 2 element (since the
// last element will always be the summary -- 'create mode ... ')
return (!isNaN(item) && (
index + 2 === arr.length ||
!isNaN(arr[index+1])))
});
if (timeSpan) {
const date = new Date(parseInt(timeSpan, 10) * 1000);
return date.toLocaleString();
Expand Down

0 comments on commit f736f9c

Please sign in to comment.