Manufacturing a git repo for unit test

I function in node that is supposed to return a list of recently modified (1 day old) files in git. The function basically does something like

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


git log --since="" --name-only --oneline

So, I want to validate that the function does what it is supposed to do. So, in a mocha test, I have:

  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 ' +
        sh.exec('cd ' + repo + '; git add file1; git commit -m "FILE1" file1');
        sessionConfig = new Session(repo, repo);

What I am noticing is that after I create the git repo, the git commands to only return recently modified files don't seem to return a result. However, if I add file3 (the commented section), the command will work.

What I want to ultimately create is a repo that has old commits and new commits and a command that returns only recently modified files. Any suggestions appreciated!


Turns out that getting "yesterday" had some issues in dealing with timezones when converting to an ISO String.

I modified my yesterday to be midnight and now everything works.

Need Your Help

Encrypting a string with a stack

c++ encryption stack

I received an assignment for my C++ class last week. I think some of you will find it interesting! I managed to get most of the code down but I'm stuck and cannot figure this out for the life of me...