forked from nanjizal/code-cookbook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGitUtil.hx
45 lines (40 loc) · 1.23 KB
/
GitUtil.hx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package;
using StringTools;
/**
* @author Mark Knol
*/
class GitUtil
{
static function getCreationDate(path:String):Date {
#if !display
var process = new sys.io.Process('git', ['log','--diff-filter=A','--follow','--date=short','--format=%ad', '-1', '--', path]);
if (process.exitCode() != 0) throw process.stderr.readAll().toString();
var dateString = process.stdout.readAll().toString();
dateString = dateString.replace("\n", "").replace("\r", "");
return Date.fromString(dateString);
#else
return null;
#end
}
static function getModificationDate(path:String):Date {
#if !display
var process = new sys.io.Process('git', ['log','--date=short','--format=%ad', '-1', '--', path]);
if (process.exitCode() != 0) throw process.stderr.readAll().toString();
var dateString = process.stdout.readAll().toString();
dateString = dateString.replace("\n", "").replace("\r", "");
return Date.fromString(dateString);
#else
return null;
#end
}
public static function getStat(path:String):GitDates {
return {
modified: getModificationDate(path),
created: getCreationDate(path),
}
}
}
typedef GitDates = {
modified: Date,
created: Date,
}