2014-01-28 33 views
1

我在應該返回git中最近修改(1天前)文件列表的節點中運行。功能基本上沒有像製造單元測試的git回購

git diff --name-only $(git rev-list -n1 --before="1 day ago" HEAD) 

git log --since="1.day" --name-only --oneline 

所以,我想驗證功能做的事情是應該做的。所以,在摩卡測試,我有:

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命令只返回最近修改的文件似乎並沒有返回結果。但是,如果我添加file3(註釋部分),該命令將工作。

我想最終創建的是一個具有舊提交和新提交以及僅返回最近修改的文件的命令的回購。任何建議感激!

+0

如果file1和file2是在「twodays」之前(而不是昨天)完成的,它會起作用嗎? – VonC

+0

這使我在正確的軌道上... – nathasm

回答

1

原來,在轉換爲ISO字符串時,獲取「昨天」在處理時區時遇到了一些問題。

我修改我的昨天是午夜,現在一切正常。

+0

優秀。很高興你想出來了。 +1 – VonC