我在node中的函数应该返回git中最近修改的(1天前)文件的列表。该函数的基本功能如下
git diff --name-only $(git rev-list -n1 --before="1 day ago" HEAD)或
git log --since="1.day" --name-only --oneline所以,我想验证这个函数是否做了它应该做的事情。所以,在mocha测试中,我有:
var tmp = require('tmp');
describe('Git test', function() {
var today = new Date();
var threedays = new Date();
var yesterday = new Date();
threedays.setDate(today.getDate() - 3);
yesterday.setDate(today.getDate() - 1);
beforeEach(function(done) {
tmp.dir({ template: '/tmp/test-XXXXXX', unsafeCleanup: true },
function _tempDirCreated(err, path) {
if (err) { throw err; }
repo = path;
sh.exec('cd ' + repo + '; git init');
sh.exec('touch ' + repo + '/file1');
sh.exec('touch ' + repo + '/file2');
//sh.exec('touch ' + repo + '/file3');
//sh.exec('cd ' + repo + '; git add file3; GIT_COMMITTER_DATE="' +
// threedays.toISOString() +
// '" git commit -m "file3" file3 --date ' + threedays.toISOString());
sh.exec('cd ' + repo + '; git add file2; GIT_COMMITTER_DATE="' +
yesterday.toISOString() + '" git commit -m "FILE2" file2 --date ' +
yesterday.toISOString());
sh.exec('cd ' + repo + '; git add file1; git commit -m "FILE1" file1');
sessionConfig = new Session(repo, repo);
done();
}
);
});我注意到的是,在我创建git存储库之后,只返回最近修改过的文件的git命令似乎没有返回结果。但是,如果我添加file3 (注释部分),该命令将起作用。
我最终想要创建的是一个具有旧提交和新提交的repo,以及一个只返回最近修改过的文件的命令。非常感谢您的任何建议!
发布于 2014-01-29 23:41:31
原来,在转换为ISO字符串时,获取“昨天”在处理时区时出现了一些问题。
我把昨天的时间改成了午夜,现在一切正常。
https://stackoverflow.com/questions/21396039
复制相似问题