예제 #1
0
    def test_get_revision_before_date_stays_on_current_branch(self):
        #create repo
        gitrepo = GitRepository(self.directory, init=True)
        
        #make a few commits
        date_of_target_commit = datetime(2011, 10, 28, 8, 5, 0)
        self.create_single_file_add_and_commit_it(gitrepo, date=datetime(2011, 10, 28, 8, 4, 0))
        self.create_single_file_add_and_commit_it(gitrepo, date=date_of_target_commit)
        self.create_single_file_add_and_commit_it(gitrepo, date=datetime(2011, 10, 28, 8, 6, 0))
        self.create_single_file_add_and_commit_it(gitrepo, date=datetime(2011, 10, 28, 8, 7, 0))

        #get sha1 of target commit (since we know it is the second commit)
        target_sha1 = gitrepo.run_git("log --format=%H --skip=2 -1")
        target_sha1 = target_sha1.strip()
        
        #create a new branch and commits on it, with one commit that would be
        #a better match for the requested date, except it is on a different branch
        gitrepo.create_branch("newbranch")
        gitrepo.switch_to_revision("newbranch")
        self.create_single_file_add_and_commit_it(gitrepo, date=datetime(2011, 10, 28, 8, 4, 0))
        self.create_single_file_add_and_commit_it(gitrepo, date=datetime(2011, 10, 28, 8, 5, 30))
        self.create_single_file_add_and_commit_it(gitrepo, date=datetime(2011, 10, 28, 8, 6, 0))

        #make sure when we ask for sha1 of the commit before a date we get the right one
        gitrepo.switch_to_revision("master")
        actual_sha1 = gitrepo.get_revision_before_date(datetime(2011, 10, 28, 8, 5, 45))
        eq_(target_sha1, actual_sha1)
예제 #2
0
    def test_get_revision_before_date(self):
        #create repo
        gitrepo = GitRepository(self.directory, init=True)
        
        #make a few commits
        date_of_target_commit = datetime(2011, 10, 28, 8, 5, 0)
        self.create_single_file_add_and_commit_it(gitrepo, date=datetime(2011, 10, 28, 8, 4, 0))
        self.create_single_file_add_and_commit_it(gitrepo, date=date_of_target_commit)
        self.create_single_file_add_and_commit_it(gitrepo, date=datetime(2011, 10, 28, 8, 6, 0))
        self.create_single_file_add_and_commit_it(gitrepo, date=datetime(2011, 10, 28, 8, 7, 0))

        #get sha1 of target commit (since we know it is the second commit)
        target_sha1 = gitrepo.run_git("log --format=%H --skip=2 -1")
        target_sha1 = target_sha1.strip()

        #make sure when we ask for sha1 of the commit before a date we get the right one
        actual_sha1 = gitrepo.get_revision_before_date(datetime(2011, 10, 28, 8, 5, 45))
        eq_(target_sha1, actual_sha1)
예제 #3
0
    def test_get_revision_before_date_can_find_commits_later_than_current_working_directory(self):
        #create repo
        gitrepo = GitRepository(self.directory, init=True)
        
        #make a few commits
        target_date = datetime(2011, 11, 1, 20, 38, 0)
        self.create_single_file_add_and_commit_it(gitrepo, date=datetime(2011, 11, 1, 20, 35, 0))
        self.create_single_file_add_and_commit_it(gitrepo, date=datetime(2011, 11, 1, 20, 36, 0))
        self.create_single_file_add_and_commit_it(gitrepo, date=datetime(2011, 11, 1, 20, 37, 0))
        self.create_single_file_add_and_commit_it(gitrepo, date=target_date)

        #get sha1 of an early and a late commit
        early_sha1 = gitrepo.run_git("log --format=%H --skip=2 -1").strip()
        late_sha1 = gitrepo.run_git("log --format=%H -1").strip()
       
        #switch to early_sha1
        gitrepo.switch_to_revision(early_sha1)
        
        #make sure when we ask for sha1 of the commit before a date we get the right one
        actual_sha1 = gitrepo.get_revision_before_date(datetime(2011, 11, 1, 20, 38, 30))
        eq_(late_sha1, actual_sha1)