示例#1
0
    def test_diff(self):
        """Tests the `diff` method"""
        r = Repo.init(self.path, mkdir=True)

        with open(os.path.join(r.root, 'test'), 'w') as fp:
            fp.write('hello world')
        r.add(all=True)
        c1 = r.commit(committer='Test McGee', message='testing diff 1')

        with open(os.path.join(r.root, 'test'), 'w') as fp:
            fp.write('hello world!')
        r.add(all=True)
        c2 = r.commit(committer='Test McGee', message='testing diff 2')

        expected = \
"""*** 

--- 

***************

*** 1 ****

! hello world!
--- 1 ----

! hello world"""

        result = r.diff(c2.id, c1.id, 'test')

        assert result == expected
示例#2
0
    def test_diff(self):
        """Tests the `diff` method"""
        r = Repo.init(self.path, mkdir=True)

        with open(os.path.join(r.root, 'test'), 'w') as fp:
            fp.write('hello world')
        r.add(all=True)
        c1 = r.commit(committer='Test McGee', message='testing diff 1')

        with open(os.path.join(r.root, 'test'), 'w') as fp:
            fp.write('hello world!')
        r.add(all=True)
        c2 = r.commit(committer='Test McGee', message='testing diff 2')

        expected = \
"""*** 

--- 

***************

*** 1 ****

! hello world!
--- 1 ----

! hello world"""

        result = r.diff(c2.id, c1.id, 'test')

        assert result == expected
示例#3
0
    def new(cls, path):
        """
        Create and return tracker at the given path.

        :param path: path to create the directory at. For example,
                     supplying ``my_tracker`` would create the directory
                     ``./my_tracker``.
        """
        # remove trailing slash
        if path.endswith('/'):
            path = path[:-1]

        # set the install paths
        paths = {
            'root': path,
            'issues': os.path.join(path, 'issues'),
            'admin': os.path.join(path, '.hopper'),
            'docs': os.path.join(path, 'docs')
        }

        # create the repository
        repo = Repo.init(paths['root'], mkdir=True)

        # build the default structure
        open(os.path.join(paths['root'], 'config'), 'w').close()
        os.mkdir(paths['issues'])
        open(os.path.join(paths['issues'], 'empty'), 'w').close()
        os.mkdir(paths['admin'])
        open(os.path.join(paths['admin'], 'empty'), 'w').close()
        os.mkdir(paths['docs'])

        # read sample docs from packaged `templates` into `docs`.
        templates = os.path.join(os.path.dirname(__file__), 'templates')
        for p in os.listdir(templates):
            with open(os.path.join(templates, p), 'r') as fp:
                data = fp.read()
            with open(os.path.join(paths['docs'], p), 'w') as fp:
                fp.write(data)

        # init the class
        tracker = cls(path)

        # set the config
        config = TrackerConfig(tracker)
        config.name = os.path.basename(path).capitalize()
        config.save()

        # add everything to the repo and commit
        repo.add(all=True)
        repo.commit(committer='Hopper <*****@*****.**>',
                    message='Created the %s tracker' % config.name)

        # instantiate and return our new Tracker.
        return tracker
示例#4
0
    def new(cls, path):
        """
        Create and return tracker at the given path.

        :param path: path to create the directory at. For example,
                     supplying ``my_tracker`` would create the directory
                     ``./my_tracker``.
        """
        # remove trailing slash
        if path.endswith("/"):
            path = path[:-1]

        # set the install paths
        paths = {
            "root": path,
            "issues": os.path.join(path, "issues"),
            "admin": os.path.join(path, ".hopper"),
            "docs": os.path.join(path, "docs"),
        }

        # create the repository
        repo = Repo.init(paths["root"], mkdir=True)

        # build the default structure
        open(os.path.join(paths["root"], "config"), "w").close()
        os.mkdir(paths["issues"])
        open(os.path.join(paths["issues"], "empty"), "w").close()
        os.mkdir(paths["admin"])
        open(os.path.join(paths["admin"], "empty"), "w").close()
        os.mkdir(paths["docs"])

        # read sample docs from packaged `templates` into `docs`.
        templates = os.path.join(os.path.dirname(__file__), "templates")
        for p in os.listdir(templates):
            with open(os.path.join(templates, p), "r") as fp:
                data = fp.read()
            with open(os.path.join(paths["docs"], p), "w") as fp:
                fp.write(data)

        # init the class
        tracker = cls(path)

        # set the config
        config = TrackerConfig(tracker)
        config.name = os.path.basename(path).capitalize()
        config.save()

        # add everything to the repo and commit
        repo.add(all=True)
        repo.commit(committer="Hopper <*****@*****.**>", message="Created the %s tracker" % config.name)

        # instantiate and return our new Tracker.
        return tracker
示例#5
0
    def test_constructor(self):
        r1 = Repo.init(self.path, mkdir=True)

        # verify that an existing repository can be initialized
        r2 = Repo(r1.root)

        # make sure it's a Repo object.
        assert type(r2) is Repo

        # a new repo should have no HEAD
        try:
            r2.head()
        except NoHeadSet:
            pass
示例#6
0
    def test_constructor(self):
        r1 = Repo.init(self.path, mkdir=True)

        # verify that an existing repository can be initialized
        r2 = Repo(r1.root)

        # make sure it's a Repo object.
        assert type(r2) is Repo

        # a new repo should have no HEAD
        try:
            r2.head()
        except NoHeadSet:
            pass
示例#7
0
 def _repo_with_commits(self, num_commits=1):
     """
     Returns a repo with one or more commits, on master branch, with
     a tag 'v1.0' that points to the last commit.
     """
     r = Repo.init(self.path, mkdir=True)
     for c in range(num_commits):
         for i in range(4):
             self._rand_file('spam-%d' % i)
         # add the files/changes
         r.add(all=True)
         # commit the changes
         r.commit(committer='Joe Sixpack', message='Commit %d' % c)
     r.tag('v1.0')
     return r
示例#8
0
    def test_init(self):
        """Tests the `init` method"""
        # NOTE init refers not to __init__, but the classmethod for creating 
        # repositories. See test_constructor() for __init__.

        r = Repo.init(self.path, mkdir=True)

        # make sure it created something.
        assert os.path.isdir(self.path)

        # does the dir have a .git?
        assert os.path.isdir(os.path.join(self.path, '.git'))

        # make sure it returns a Repo object.
        assert type(r) is Repo
示例#9
0
    def test_commit(self):
        """Tests the `commit` method"""
        r = Repo.init(self.path, mkdir=True)
        self._rand_file('spam')
        r.add('spam')

        c = r.commit(committer='GOB Bluth', message='Come on!')

        # make sure the commit got set right
        assert type(c) is Commit
        assert c.author == 'GOB Bluth'
        assert c.message == 'Come on!'

        # the commit should be the same as the Repo.head
        assert c == r.head()
示例#10
0
 def _repo_with_commits(self, num_commits=1):
     """
     Returns a repo with one or more commits, on master branch, with
     a tag 'v1.0' that points to the last commit.
     """
     r = Repo.init(self.path, mkdir=True)
     for c in range(num_commits):
         for i in range(4):
             self._rand_file('spam-%d' % i)
         # add the files/changes
         r.add(all=True)
         # commit the changes
         r.commit(committer='Joe Sixpack', message='Commit %d' % c)
     r.tag('v1.0')
     return r
示例#11
0
    def test_init(self):
        """Tests the `init` method"""
        # NOTE init refers not to __init__, but the classmethod for creating
        # repositories. See test_constructor() for __init__.

        r = Repo.init(self.path, mkdir=True)

        # make sure it created something.
        assert os.path.isdir(self.path)

        # does the dir have a .git?
        assert os.path.isdir(os.path.join(self.path, '.git'))

        # make sure it returns a Repo object.
        assert type(r) is Repo
示例#12
0
    def test_commit(self):
        """Tests the `commit` method"""
        r = Repo.init(self.path, mkdir=True)
        self._rand_file('spam')
        r.add('spam')

        c = r.commit(committer='GOB Bluth', message='Come on!')

        # make sure the commit got set right
        assert type(c) is Commit
        assert c.author == 'GOB Bluth'
        assert c.message == 'Come on!'

        # the commit should be the same as the Repo.head
        assert c == r.head()