示例#1
0
def create_commit(data, marker='Default', blob=None):
    if not blob:
        blob = Blob.from_string('The blob content %s' % marker)
    tree = Tree()
    tree.add("thefile_%s" % marker, 0o100644, blob.id)
    cmt = Commit()
    if data:
        assert isinstance(data[-1], Commit)
        cmt.parents = [data[-1].id]
    cmt.tree = tree.id
    author = "John Doe %s <*****@*****.**>" % marker
    cmt.author = cmt.committer = author
    tz = parse_timezone('-0200')[0]
    cmt.commit_time = cmt.author_time = int(time())
    cmt.commit_timezone = cmt.author_timezone = tz
    cmt.encoding = "UTF-8"
    cmt.message = "The commit message %s" % marker
    tag = Tag()
    tag.tagger = "*****@*****.**"
    tag.message = "Annotated tag"
    tag.tag_timezone = parse_timezone('-0200')[0]
    tag.tag_time = cmt.author_time
    tag.object = (Commit, cmt.id)
    tag.name = "v_%s_0.1" % marker
    return blob, tree, tag, cmt
示例#2
0
def create_commit(data, marker='Default', blob=None):
    if not blob:
        blob = Blob.from_string('The blob content %s' % marker)
    tree = Tree()
    tree.add("thefile_%s" % marker, 0o100644, blob.id)
    cmt = Commit()
    if data:
        assert isinstance(data[-1], Commit)
        cmt.parents = [data[-1].id]
    cmt.tree = tree.id
    author = "John Doe %s <*****@*****.**>" % marker
    cmt.author = cmt.committer = author
    tz = parse_timezone('-0200')[0]
    cmt.commit_time = cmt.author_time = int(time())
    cmt.commit_timezone = cmt.author_timezone = tz
    cmt.encoding = "UTF-8"
    cmt.message = "The commit message %s" % marker
    tag = Tag()
    tag.tagger = "*****@*****.**"
    tag.message = "Annotated tag"
    tag.tag_timezone = parse_timezone('-0200')[0]
    tag.tag_time = cmt.author_time
    tag.object = (Commit, cmt.id)
    tag.name = "v_%s_0.1" % marker
    return blob, tree, tag, cmt
def create_commit(data, marker=b"Default", blob=None):
    if not blob:
        blob = Blob.from_string(b"The blob content " + marker)
    tree = Tree()
    tree.add(b"thefile_" + marker, 0o100644, blob.id)
    cmt = Commit()
    if data:
        assert isinstance(data[-1], Commit)
        cmt.parents = [data[-1].id]
    cmt.tree = tree.id
    author = b"John Doe " + marker + b" <*****@*****.**>"
    cmt.author = cmt.committer = author
    tz = parse_timezone(b"-0200")[0]
    cmt.commit_time = cmt.author_time = int(time())
    cmt.commit_timezone = cmt.author_timezone = tz
    cmt.encoding = b"UTF-8"
    cmt.message = b"The commit message " + marker
    tag = Tag()
    tag.tagger = b"*****@*****.**"
    tag.message = b"Annotated tag"
    tag.tag_timezone = parse_timezone(b"-0200")[0]
    tag.tag_time = cmt.author_time
    tag.object = (Commit, cmt.id)
    tag.name = b"v_" + marker + b"_0.1"
    return blob, tree, tag, cmt
示例#4
0
	def oldcreate(self, name):
		"""
		create a new repo
		
		:param name: the name to give the new repo
		:type name: string
		"""
		repo = Repo.init_bare(name)
	
		from dulwich.objects import Tree
		tree = Tree()
		
		from dulwich.objects import Commit, parse_timezone
		from time import time
		commit = Commit()
		commit.tree = tree.id	#is the tree.id the sha1 of the files contained in tree
		author = "New Project Wizard <wizard@host>"
		commit.author = commit.committer = author
		commit.commit_time = commit.author_time = int(time())
		tz = parse_timezone('+1000')[0]
		commit.commit_timezone = commit.author_timezone = tz
		commit.encoding = "UTF-8"
		commit.message = "New Project."
	
		object_store = repo.object_store

		#then add the tree
		object_store.add_object(tree)
		#then add the commit
		object_store.add_object(commit)
		
		repo.refs['refs/heads/master'] = commit.id
		
		return {"success":"%s.git created" % name}
示例#5
0
def step_impl_given(context):
    context.test_git_repo_dir = tempfile.mkdtemp(
        "paasta_tools_deployments_json_itest")
    context.test_git_repo = Repo.init(context.test_git_repo_dir)
    print("Temp repo in %s" % context.test_git_repo_dir)

    blob = Blob.from_string(b"My file content\n")
    tree = Tree()
    tree.add(b"spam", 0o0100644, blob.id)

    commit = Commit()
    commit.author = commit.committer = b"itest author"
    commit.commit_time = commit.author_time = int(time())
    commit.commit_timezone = commit.author_timezone = parse_timezone(
        b"-0200")[0]
    commit.message = b"Initial commit"
    commit.tree = tree.id

    object_store = context.test_git_repo.object_store
    object_store.add_object(blob)
    object_store.add_object(tree)
    object_store.add_object(commit)

    context.test_git_repo.refs[b"refs/heads/master"] = commit.id
    context.expected_commit_as_bytes = commit.id
    context.expected_commit = context.expected_commit_as_bytes.decode()

    context.image_version = None
示例#6
0
    def delete_file(self, subdir, filename, commit_msg):
        try:
            subdir_tree = _walk_git_repo_tree(self.repo, self.current_tree,
                                              subdir)
        except KeyError:
            raise FileNotFoundException('No subdir named %r' % subdir)
        if not filename in subdir_tree:
            raise FileNotFoundException('%r not in %s' % (filename, subdir))
        del subdir_tree[filename]

        # create new root tree
        tree = self.current_tree
        tree.add(stat.S_IFDIR, subdir, subdir_tree.id)

        # create commit
        # FIXME: factor this out!
        commit = Commit()
        commit.parents = [self.current_commit.id]
        commit.tree = tree.id
        commit.author = commit.committer = self.wiki_user
        commit.commit_time = commit.author_time = int(time.time())
        commit.commit_timezone = commit.author_timezone = parse_timezone(
            time.timezone)[0]
        commit.encoding = 'UTF-8'
        commit.message = commit_msg.encode('utf-8')

        # store all objects
        self.repo.object_store.add_object(subdir_tree)
        self.repo.object_store.add_object(tree)
        self.repo.object_store.add_object(commit)

        # update the branch
        self.repo.refs[self.head] = commit.id
示例#7
0
def step_impl_given(context):
    context.test_git_repo_dir = tempfile.mkdtemp(
        'paasta_tools_deployments_json_itest')
    context.test_git_repo = Repo.init(context.test_git_repo_dir)
    print 'Temp repo in %s' % context.test_git_repo_dir

    blob = Blob.from_string("My file content\n")
    tree = Tree()
    tree.add("spam", 0100644, blob.id)

    commit = Commit()
    commit.author = commit.committer = "itest author"
    commit.commit_time = commit.author_time = int(time())
    commit.commit_timezone = commit.author_timezone = parse_timezone(
        '-0200')[0]
    commit.message = "Initial commit"
    commit.tree = tree.id

    object_store = context.test_git_repo.object_store
    object_store.add_object(blob)
    object_store.add_object(tree)
    object_store.add_object(commit)

    context.test_git_repo.refs['refs/heads/master'] = commit.id
    context.expected_commit = commit.id
示例#8
0
文件: start.py 项目: Swizec/OS2
def init_the_git(config):
    path = config.get('Local', 'path')

    repo = Repo.init(path)
    blob = Blob.from_string(open(os.path.join(path, '.git-dropbox.cnf')).read())

    tree = Tree()
    tree.add(".git-dropbox.cnf", 0100644, blob.id)

    commit = Commit()
    commit.tree = tree.id
    commit.author = config.get('Local', 'user')
    commit.committer = 'Git-dropbox'
    commit.commit_time = int(time())
    commit.author_time = os.path.getctime(os.path.join(path, '.git-dropbox.cnf'))
    commit.commit_timezone = commit.author_timezone = parse_timezone('-0200')[0]
    commit.encoding = 'UTF-8'
    commit.message = 'Initial commit'

    object_store = repo.object_store
    object_store.add_object(blob)
    object_store.add_object(tree)
    object_store.add_object(commit)

    repo.refs['refs/heads/master'] = commit.id
示例#9
0
文件: start.py 项目: Swizec/OS2
def init_the_git(config):
    path = config.get('Local', 'path')

    repo = Repo.init(path)
    blob = Blob.from_string(
        open(os.path.join(path, '.git-dropbox.cnf')).read())

    tree = Tree()
    tree.add(".git-dropbox.cnf", 0100644, blob.id)

    commit = Commit()
    commit.tree = tree.id
    commit.author = config.get('Local', 'user')
    commit.committer = 'Git-dropbox'
    commit.commit_time = int(time())
    commit.author_time = os.path.getctime(
        os.path.join(path, '.git-dropbox.cnf'))
    commit.commit_timezone = commit.author_timezone = parse_timezone(
        '-0200')[0]
    commit.encoding = 'UTF-8'
    commit.message = 'Initial commit'

    object_store = repo.object_store
    object_store.add_object(blob)
    object_store.add_object(tree)
    object_store.add_object(commit)

    repo.refs['refs/heads/master'] = commit.id
示例#10
0
    def test_push_annotated_tag(self):
        def determine_wants(*args):
            return {
                "refs/heads/master": local_repo.refs["HEAD"],
                "refs/tags/v1.0": local_repo.refs["refs/tags/v1.0"]
            }

        local_repo = repo.Repo.init(self.temp_d, mkdir=True)
        # Nothing in the staging area
        sha = local_repo.do_commit('Test commit', 'fbo@localhost')
        otype, data = local_repo.object_store.get_raw(sha)
        commit = objects.ShaFile.from_raw_string(otype, data)
        tag = objects.Tag()
        tag.tagger = "fbo@localhost"
        tag.message = "Annotated tag"
        tag.tag_timezone = objects.parse_timezone('-0200')[0]
        tag.tag_time = commit.author_time
        tag.object = (objects.Commit, commit.id)
        tag.name = "v0.1"
        local_repo.object_store.add_object(tag)
        local_repo.refs['refs/tags/v1.0'] = tag.id
        swift.SwiftRepo.init_bare(self.scon, self.conf)
        tcp_client = client.TCPGitClient(self.server_address, port=self.port)
        tcp_client.send_pack(self.fakerepo, determine_wants,
                             local_repo.object_store.generate_pack_contents)
        swift_repo = swift.SwiftRepo(self.fakerepo, self.conf)
        tag_sha = swift_repo.refs.read_loose_ref('refs/tags/v1.0')
        otype, data = swift_repo.object_store.get_raw(tag_sha)
        rtag = objects.ShaFile.from_raw_string(otype, data)
        self.assertEqual(rtag.object[1], commit.id)
        self.assertEqual(rtag.id, tag.id)
示例#11
0
def git_repo_init(gitdir):
    os.mkdir(gitdir)
    repo = Repo.init_bare(gitdir)
    blob = Blob.from_string("""Why, Hello there!

This is your friendly Legislation tracker, Billy here.

This is a git repo full of everything I write to the DB. This isn't super
useful unless you're debugging production issues.

Fondly,
   Bill, your local Billy instance.""")
    tree = Tree()
    tree.add("README", 0100644, blob.id)
    commit = Commit()
    commit.tree = tree.id
    author = "Billy <billy@localhost>"
    commit.author = commit.committer = author
    commit.commit_time = commit.author_time = int(time())
    tz = parse_timezone('-0400')[0]
    commit.commit_timezone = commit.author_timezone = tz
    commit.encoding = "UTF-8"
    commit.message = "Initial commit"
    repo.object_store.add_object(blob)
    repo.object_store.add_object(tree)
    repo.object_store.add_object(commit)
    repo.refs['refs/heads/master'] = commit.id
示例#12
0
def create_commit(repo,
                  files=None,
                  tree=None,
                  parent=None,
                  author=AUTHOR,
                  message="No message given"):
    object_store = repo.object_store
    if not tree:
        tree = Tree()
    for f in files:
        blob = Blob.from_string(f[2])
        object_store.add_object(blob)
        tree.add(f[0], f[1], blob.id)
    commit = Commit()
    if parent:
        commit.parents = [parent]
    else:
        commit.parents = []
    # Check that we have really updated the tree
    if parent:
        parent_commit = repo.get_object(parent)
        if parent_commit.tree == tree.id:
            raise NoChangesException()
    commit.tree = tree.id
    commit.author = commit.committer = author
    commit.commit_time = commit.author_time = get_ts()
    tz = parse_timezone('+0100')[0]
    commit.commit_timezone = commit.author_timezone = tz
    commit.encoding = "UTF-8"
    commit.message = message

    object_store.add_object(tree)
    object_store.add_object(commit)
    return commit
示例#13
0
文件: db.py 项目: mbr/qwapp
	def _update_file(self, name, subdir, filename, data, commit_msg):
		# first, create a new blob for the data
		blob = Blob.from_string(data.encode('utf-8'))

		# fetch the old tree object, add new page
		try:
			subdir_tree = _walk_git_repo_tree(self.repo, self.current_tree, subdir)
		except KeyError:
			# we need to create the subdir_tree as well, since it does not exist
			# yet
			subdir_tree = Tree()
		subdir_tree.add(_git_default_file_mode, filename, blob.id)

		# create new root tree
		tree = self.current_tree
		tree.add(stat.S_IFDIR, subdir, subdir_tree.id)

		# create commit
		commit = Commit()
		commit.parents = [self.current_commit.id]
		commit.tree = tree.id
		commit.author = commit.committer = self.wiki_user
		commit.commit_time =  commit.author_time = int(time.time())
		commit.commit_timezone = commit.author_timezone = parse_timezone(time.timezone)[0]
		commit.encoding = 'UTF-8'
		commit.message = commit_msg.encode('utf-8')

		# store all objects
		self.repo.object_store.add_object(blob)
		self.repo.object_store.add_object(subdir_tree)
		self.repo.object_store.add_object(tree)
		self.repo.object_store.add_object(commit)

		# update the branch
		self.repo.refs[self.head] = commit.id
示例#14
0
文件: logsave.py 项目: ekeijl/BeAT
def __init_code__():
	# initialize the repo if it doesn't exists, or load it if it does

	if not path.exists(LOGS_PATH):
		print "creating folder "+ LOGS_PATH
		mkdir(LOGS_PATH)
		repo = Repo.init(LOGS_PATH)
		blob = Blob.from_string("data")
		tree =Tree()
		tree.add(0100644, "initfile", blob.id)
		c = Commit()
		c.tree = tree.id
		author = "Writer [email protected]"
		c.author=c.committer=author
		c.commit_time=c.author_time=int(time())
		tz = parse_timezone('+0200')
		c.commit_timezone=c.author_timezone=tz
		c.encoding="UTF-8"
		c.message="initial commit"
		store = repo.object_store
		store.add_object(blob)
		store.add_object(tree)
		store.add_object(c)
		repo.refs['refs/heads/master'] = c.id
		repo.refs['HEAD'] = 'ref: refs/heads/master'
		print "success!"
	else:
		#this is how to create a Repo object from an existing repository
		from dulwich.errors import NotGitRepository
		try:
			repo = Repo(LOGS_PATH)
		except NotGitRepository as e:
			raise GitFileError("Error: the path %s exists but is not a git repository."%LOGS_PATH)
	return repo
示例#15
0
文件: bills.py 项目: VersaHQ/billy
def git_commit(message):
    if not hasattr(settings, "ENABLE_GIT") or not settings.ENABLE_GIT:
        return

    print("Commiting import as '%s'" % message)

    global git_active_repo
    global git_active_tree
    global git_old_tree
    global git_active_commit
    global HEAD
    repo = git_active_repo

    if git_old_tree == git_active_tree.id:
        # We don't wait t commit twice.
        print("Nothing new here. Bailing out.")
        return

    c = git_active_commit
    c.tree = git_active_tree.id
    c.parents = [HEAD]
    repo.object_store.add_object(git_active_tree)
    c.author = c.committer = "Billy <billy@localhost>"
    c.commit_time = c.author_time = int(time())
    tz = parse_timezone("-0400")[0]
    c.commit_timezone = c.author_timezone = tz
    c.encoding = "UTF-8"
    c.message = message
    repo.object_store.add_object(c)
    repo.refs['refs/heads/master'] = c.id
示例#16
0
def git_commit(message):
    if not hasattr(settings, "ENABLE_GIT") or not settings.ENABLE_GIT:
        return

    print("Commiting import as '%s'" % message)

    global git_active_repo
    global git_active_tree
    global git_old_tree
    global git_active_commit
    global HEAD
    repo = git_active_repo

    if git_old_tree == git_active_tree.id:
        # We don't wait t commit twice.
        print("Nothing new here. Bailing out.")
        return

    c = git_active_commit
    c.tree = git_active_tree.id
    c.parents = [HEAD]
    repo.object_store.add_object(git_active_tree)
    c.author = c.committer = "Billy <billy@localhost>"
    c.commit_time = c.author_time = int(time())
    tz = parse_timezone("-0400")[0]
    c.commit_timezone = c.author_timezone = tz
    c.encoding = "UTF-8"
    c.message = message
    repo.object_store.add_object(c)
    repo.refs['refs/heads/master'] = c.id
示例#17
0
文件: bills.py 项目: VersaHQ/billy
def git_repo_init(gitdir):
    os.mkdir(gitdir)
    repo = Repo.init_bare(gitdir)
    blob = Blob.from_string("""Why, Hello there!

This is your friendly Legislation tracker, Billy here.

This is a git repo full of everything I write to the DB. This isn't super
useful unless you're debugging production issues.

Fondly,
   Bill, your local Billy instance.""")
    tree = Tree()
    tree.add("README", 0100644, blob.id)
    commit = Commit()
    commit.tree = tree.id
    author = "Billy <billy@localhost>"
    commit.author = commit.committer = author
    commit.commit_time = commit.author_time = int(time())
    tz = parse_timezone('-0400')[0]
    commit.commit_timezone = commit.author_timezone = tz
    commit.encoding = "UTF-8"
    commit.message = "Initial commit"
    repo.object_store.add_object(blob)
    repo.object_store.add_object(tree)
    repo.object_store.add_object(commit)
    repo.refs['refs/heads/master'] = commit.id
示例#18
0
 def test_push_annotated_tag(self):
     def determine_wants(*args):
         return {"refs/heads/master": local_repo.refs["HEAD"],
                 "refs/tags/v1.0": local_repo.refs["refs/tags/v1.0"]}
     local_repo = repo.Repo.init(self.temp_d, mkdir=True)
     # Nothing in the staging area
     sha = local_repo.do_commit('Test commit', 'fbo@localhost')
     otype, data = local_repo.object_store.get_raw(sha)
     commit = objects.ShaFile.from_raw_string(otype, data)
     tag = objects.Tag()
     tag.tagger = "fbo@localhost"
     tag.message = "Annotated tag"
     tag.tag_timezone = objects.parse_timezone('-0200')[0]
     tag.tag_time = commit.author_time
     tag.object = (objects.Commit, commit.id)
     tag.name = "v0.1"
     local_repo.object_store.add_object(tag)
     local_repo.refs['refs/tags/v1.0'] = tag.id
     swift.SwiftRepo.init_bare(self.scon, self.conf)
     tcp_client = client.TCPGitClient(self.server_address,
                                      port=self.port)
     tcp_client.send_pack(self.fakerepo,
                          determine_wants,
                          local_repo.object_store.generate_pack_contents)
     swift_repo = swift.SwiftRepo(self.fakerepo, self.conf)
     tag_sha = swift_repo.refs.read_loose_ref('refs/tags/v1.0')
     otype, data = swift_repo.object_store.get_raw(tag_sha)
     rtag = objects.ShaFile.from_raw_string(otype, data)
     self.assertEqual(rtag.object[1], commit.id)
     self.assertEqual(rtag.id, tag.id)
示例#19
0
 def __init__(self, author):
     """Do not instantiate directly, use create_repo or open_repo."""
     self._author = author
     self._encoding = "UTF-8"
     self._time_zone = parse_timezone("+0000")[0]
     self.commit = sentinel
     self.tree = sentinel
示例#20
0
文件: db.py 项目: mbr/qwapp
	def delete_file(self, subdir, filename, commit_msg):
		try:
			subdir_tree = _walk_git_repo_tree(self.repo, self.current_tree, subdir)
		except KeyError:
			raise FileNotFoundException('No subdir named %r' % subdir)
		if not filename in subdir_tree: raise FileNotFoundException('%r not in %s' % (filename, subdir))
		del subdir_tree[filename]

		# create new root tree
		tree = self.current_tree
		tree.add(stat.S_IFDIR, subdir, subdir_tree.id)

		# create commit
		# FIXME: factor this out!
		commit = Commit()
		commit.parents = [self.current_commit.id]
		commit.tree = tree.id
		commit.author = commit.committer = self.wiki_user
		commit.commit_time =  commit.author_time = int(time.time())
		commit.commit_timezone = commit.author_timezone = parse_timezone(time.timezone)[0]
		commit.encoding = 'UTF-8'
		commit.message = commit_msg.encode('utf-8')

		# store all objects
		self.repo.object_store.add_object(subdir_tree)
		self.repo.object_store.add_object(tree)
		self.repo.object_store.add_object(commit)

		# update the branch
		self.repo.refs[self.head] = commit.id
示例#21
0
def _create_commit(tree, reason='', branch=False, parents=None, request=None):
    """ Creates a new commit based on the provided information. """

    commit = Commit()

    if request and 'flatpages.git.author_name' in request.registry.settings:
        author = request.registry.settings['flatpages.git.author_name']
    else:
        author = 'Anonymous'

    if request and 'flatpages.git.author_email' in request.registry.settings:
        author_email = request.registry.settings['flatpages.git.author_email']
        author = '{0} <{1}>'.format(author, author_email)

    else:
        if request:
            author = '{0} <anonymous@{0}>'.format(request.host)
        else:
            author = '{0} <anonymous@{0}example.com>'

    # TODO: Right now, all times are in UTC time. Even though everything should
    # use UTC time in a perfect world - this isn't the case in the real world.
    commit.commit_timezone = commit.author_timezone = parse_timezone('0000')[0]
    commit.commit_time = commit.author_time = int(time.time())

    commit.author = commit.committer = author

    commit.tree = tree.id
    commit.encoding = 'UTF-8'
    commit.message = reason

    if parents:
        commit.parents = parents

    return commit
示例#22
0
 def __init__(self, author):
     '''Do not instantiate directly, use create_repo or open_repo.'''
     self._author = author
     self._encoding = 'UTF-8'
     self._time_zone = parse_timezone('+0000')[0]
     self.commit = sentinel
     self.tree = sentinel
示例#23
0
文件: repoman.py 项目: CENDARI/portia
 def __init__(self, author):
     '''Do not instantiate directly, use create_repo or open_repo.'''
     self._author = author
     self._encoding = 'UTF-8'
     self._time_zone = parse_timezone('+0000')[0]
     self.commit = sentinel
     self.tree = sentinel
示例#24
0
    def update_content(self, new_content, author, email, message):
        new_content = new_content.encode('UTF-8')
        author = author.encode('UTF-8')
        message = message.encode('UTF-8')
        email = email.encode('UTF-8')

        # create blob, add to existing tree
        blob = Blob.from_string(new_content)
        self.tree[self.title] = (0100644, blob.id)

        # commit
        commit = Commit()
        commit.tree = self.tree.id
        commit.parents = [self.head.id]
        commit.author = commit.committer = "%s <%s>" % (author, email)
        commit.commit_time = commit.author_time = int(time())
        tz = parse_timezone('+0100')[0]  # FIXME: get proper timezone
        commit.commit_timezone = commit.author_timezone = tz
        commit.encoding = 'UTF-8'
        commit.message = message

        # save everything
        object_store = self.repo.object_store
        object_store.add_object(blob)
        object_store.add_object(self.tree)
        object_store.add_object(commit)

        self.repo.refs['refs/heads/master'] = commit.id
示例#25
0
    def oldcreate(self, name):
        """
		create a new repo
		
		:param name: the name to give the new repo
		:type name: string
		"""
        repo = Repo.init_bare(name)

        from dulwich.objects import Tree
        tree = Tree()

        from dulwich.objects import Commit, parse_timezone
        from time import time
        commit = Commit()
        commit.tree = tree.id  #is the tree.id the sha1 of the files contained in tree
        author = "New Project Wizard <wizard@host>"
        commit.author = commit.committer = author
        commit.commit_time = commit.author_time = int(time())
        tz = parse_timezone('+1000')[0]
        commit.commit_timezone = commit.author_timezone = tz
        commit.encoding = "UTF-8"
        commit.message = "New Project."

        object_store = repo.object_store

        #then add the tree
        object_store.add_object(tree)
        #then add the commit
        object_store.add_object(commit)

        repo.refs['refs/heads/master'] = commit.id

        return {"success": "%s.git created" % name}
示例#26
0
 def __init__(self, author):
     """Do not instantiate directly, use create_repo or open_repo."""
     self._author = (author and author.username) or DEFAULT_USER
     self._encoding = 'UTF-8'
     self._time_zone = parse_timezone('+0000')[0]
     self.commit = sentinel
     self.last_commit = None
     self.tree = sentinel
     self.last_tree = None
示例#27
0
 def __init__(self, author):
     """Do not instantiate directly, use create_repo or open_repo."""
     self._author = (author and author.username) or DEFAULT_USER
     self._encoding = 'UTF-8'
     self._time_zone = parse_timezone('+0000')[0]
     self.commit = sentinel
     self.last_commit = None
     self.tree = sentinel
     self.last_tree = None
示例#28
0
    def export_hg_commit(self, rev):
        self.ui.note(_("converting revision %s\n") % hex(rev))

        oldenc = self.swap_out_encoding()

        ctx = self.repo.changectx(rev)
        extra = ctx.extra()

        commit = Commit()

        (time, timezone) = ctx.date()
        commit.author = self.get_git_author(ctx)
        commit.author_time = int(time)
        commit.author_timezone = -timezone

        if 'committer' in extra:
            # fixup timezone
            (name, timestamp, timezone) = extra['committer'].rsplit(' ', 2)
            commit.committer = name
            commit.commit_time = timestamp

            # work around a timezone format change
            if int(timezone) % 60 != 0: #pragma: no cover
                timezone = parse_timezone(timezone)
                # Newer versions of Dulwich return a tuple here
                if isinstance(timezone, tuple):
                    timezone, neg_utc = timezone
                    commit._commit_timezone_neg_utc = neg_utc
            else:
                timezone = -int(timezone)
            commit.commit_timezone = timezone
        else:
            commit.committer = commit.author
            commit.commit_time = commit.author_time
            commit.commit_timezone = commit.author_timezone

        commit.parents = []
        for parent in self.get_git_parents(ctx):
            hgsha = hex(parent.node())
            git_sha = self.map_git_get(hgsha)
            if git_sha:
                commit.parents.append(git_sha)

        commit.message = self.get_git_message(ctx)

        if 'encoding' in extra:
            commit.encoding = extra['encoding']

        tree_sha = commit_tree(self.git.object_store, self.iterblobs(ctx))
        commit.tree = tree_sha

        self.git.object_store.add_object(commit)
        self.map_set(commit.id, ctx.hex())

        self.swap_out_encoding(oldenc)
        return commit.id
def tag_create(repo,
               tag,
               author=None,
               message=None,
               annotated=False,
               objectish="HEAD",
               tag_time=None,
               tag_timezone=None,
               sign=False):
    """Creates a tag in git via dulwich calls:

    Args:
      repo: Path to repository
      tag: tag string
      author: tag author (optional, if annotated is set)
      message: tag message (optional)
      annotated: whether to create an annotated tag
      objectish: object the tag should point at, defaults to HEAD
      tag_time: Optional time for annotated tag
      tag_timezone: Optional timezone for annotated tag
      sign: GPG Sign the tag
    """

    with open_repo_closing(repo) as r:
        object = parse_object(r, objectish)

        if annotated:
            # Create the tag object
            tag_obj = Tag()
            if author is None:
                # TODO(jelmer): Don't use repo private method.
                author = r._get_user_identity(r.get_config_stack())
            tag_obj.tagger = author
            tag_obj.message = message
            tag_obj.name = tag
            tag_obj.object = (type(object), object.id)
            if tag_time is None:
                tag_time = int(time.time())
            tag_obj.tag_time = tag_time
            if tag_timezone is None:
                # TODO(jelmer) Use current user timezone rather than UTC
                tag_timezone = 0
            elif isinstance(tag_timezone, str):
                tag_timezone = parse_timezone(tag_timezone)
            tag_obj.tag_timezone = tag_timezone
            if sign:
                import gpg
                with gpg.Context(armor=True) as c:
                    tag_obj.signature, unused_result = c.sign(
                        tag_obj.as_raw_string())
            r.object_store.add_object(tag_obj)
            tag_id = tag_obj.id
        else:
            tag_id = object.id

        r.refs[_make_tag_ref(tag)] = tag_id
示例#30
0
    def export_hg_commit(self, rev):
        self.ui.note(_("converting revision %s\n") % hex(rev))

        oldenc = self.swap_out_encoding()

        ctx = self.repo.changectx(rev)
        extra = ctx.extra()

        commit = Commit()

        (time, timezone) = ctx.date()
        commit.author = self.get_git_author(ctx)
        commit.author_time = int(time)
        commit.author_timezone = -timezone

        if 'committer' in extra:
            # fixup timezone
            (name, timestamp, timezone) = extra['committer'].rsplit(' ', 2)
            commit.committer = name
            commit.commit_time = timestamp

            # work around a timezone format change
            if int(timezone) % 60 != 0: #pragma: no cover
                timezone = parse_timezone(timezone)
                # Newer versions of Dulwich return a tuple here
                if isinstance(timezone, tuple):
                    timezone, neg_utc = timezone
                    commit._commit_timezone_neg_utc = neg_utc
            else:
                timezone = -int(timezone)
            commit.commit_timezone = timezone
        else:
            commit.committer = commit.author
            commit.commit_time = commit.author_time
            commit.commit_timezone = commit.author_timezone

        commit.parents = []
        for parent in self.get_git_parents(ctx):
            hgsha = hex(parent.node())
            git_sha = self.map_git_get(hgsha)
            if git_sha:
                commit.parents.append(git_sha)

        commit.message = self.get_git_message(ctx)

        if 'encoding' in extra:
            commit.encoding = extra['encoding']

        tree_sha = commit_tree(self.git.object_store, self.iterblobs(ctx))
        commit.tree = tree_sha

        self.git.object_store.add_object(commit)
        self.map_set(commit.id, ctx.hex())

        self.swap_out_encoding(oldenc)
        return commit.id
示例#31
0
 def test_commit_double_negative_timezone(self):
     c = Commit()
     c.tree = b"cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
     c.message = b"Some message"
     c.committer = b"Committer <Committer>"
     c.commit_time = 4
     (c.commit_timezone, c._commit_timezone_neg_utc) = parse_timezone(b"--700")
     c.author_time = 5
     c.author_timezone = 60 * 2
     c.author = b"Author <author>"
     self.assertRoundtripCommit(c)
示例#32
0
def parse_reflog_line(line):
    """Parse a reflog line.

    :param line: Line to parse
    :return: Tuple of (old_sha, new_sha, committer, timestamp, timezone,
        message)
    """
    (begin, message) = line.split(b"\t", 1)
    (old_sha, new_sha, rest) = begin.split(b" ", 2)
    (committer, timestamp_str, timezone_str) = rest.rsplit(b" ", 2)
    return Entry(old_sha, new_sha, committer, int(timestamp_str), parse_timezone(timezone_str)[0], message)
示例#33
0
def parse_reflog_line(line):
    """Parse a reflog line.

    :param line: Line to parse
    :return: Tuple of (old_sha, new_sha, committer, timestamp, timezone,
        message)
    """
    (begin, message) = line.split(b'\t', 1)
    (old_sha, new_sha, rest) = begin.split(b' ', 2)
    (committer, timestamp_str, timezone_str) = rest.rsplit(b' ', 2)
    return Entry(old_sha, new_sha, committer, int(timestamp_str),
                 parse_timezone(timezone_str)[0], message)
示例#34
0
文件: commit.py 项目: Swizec/OS2
def commit(root, path, author):
    repo = Repo(root)

    repo.stage([path])

    return repo.do_commit('Automated commit',
                          committer='Git-dropbox',
                          author=author,
                          commit_timestamp=int(time()),
                          commit_timezone=parse_timezone('-0200')[0],
                          author_timestamp=os.path.getctime(os.path.join(root, path)),
                          encoding='UTF-8')
示例#35
0
def create_commit(marker=None):
    blob = Blob.from_string('The blob content %s' % marker)
    tree = Tree()
    tree.add("thefile %s" % marker, 0o100644, blob.id)
    cmt = Commit()
    cmt.tree = tree.id
    cmt.author = cmt.committer = "John Doe <*****@*****.**>"
    cmt.message = "%s" % marker
    tz = parse_timezone('-0200')[0]
    cmt.commit_time = cmt.author_time = int(time.time())
    cmt.commit_timezone = cmt.author_timezone = tz
    return cmt, tree, blob
示例#36
0
def create_commit(marker=None):
    blob = Blob.from_string(b'The blob content ' + marker)
    tree = Tree()
    tree.add(b"thefile " + marker, 0o100644, blob.id)
    cmt = Commit()
    cmt.tree = tree.id
    cmt.author = cmt.committer = b"John Doe <*****@*****.**>"
    cmt.message = marker
    tz = parse_timezone(b'-0200')[0]
    cmt.commit_time = cmt.author_time = int(time.time())
    cmt.commit_timezone = cmt.author_timezone = tz
    return cmt, tree, blob
示例#37
0
文件: commit.py 项目: Swizec/OS2
def commit(root, path, author):
    repo = Repo(root)

    repo.stage([path])

    return repo.do_commit('Automated commit',
                          committer='Git-dropbox',
                          author=author,
                          commit_timestamp=int(time()),
                          commit_timezone=parse_timezone('-0200')[0],
                          author_timestamp=os.path.getctime(
                              os.path.join(root, path)),
                          encoding='UTF-8')
示例#38
0
def tag_create(
        repo, tag, author=None, message=None, annotated=False,
        objectish="HEAD", tag_time=None, tag_timezone=None,
        sign=False):
    """Creates a tag in git via dulwich calls:

    :param repo: Path to repository
    :param tag: tag string
    :param author: tag author (optional, if annotated is set)
    :param message: tag message (optional)
    :param annotated: whether to create an annotated tag
    :param objectish: object the tag should point at, defaults to HEAD
    :param tag_time: Optional time for annotated tag
    :param tag_timezone: Optional timezone for annotated tag
    :param sign: GPG Sign the tag
    """

    with open_repo_closing(repo) as r:
        object = parse_object(r, objectish)

        if annotated:
            # Create the tag object
            tag_obj = Tag()
            if author is None:
                # TODO(jelmer): Don't use repo private method.
                author = r._get_user_identity(r.get_config_stack())
            tag_obj.tagger = author
            tag_obj.message = message
            tag_obj.name = tag
            tag_obj.object = (type(object), object.id)
            if tag_time is None:
                tag_time = int(time.time())
            tag_obj.tag_time = tag_time
            if tag_timezone is None:
                # TODO(jelmer) Use current user timezone rather than UTC
                tag_timezone = 0
            elif isinstance(tag_timezone, str):
                tag_timezone = parse_timezone(tag_timezone)
            tag_obj.tag_timezone = tag_timezone
            if sign:
                import gpg
                with gpg.Context(armor=True) as c:
                    tag_obj.signature, unused_result = c.sign(
                        tag_obj.as_raw_string())
            r.object_store.add_object(tag_obj)
            tag_id = tag_obj.id
        else:
            tag_id = object.id

        r.refs[_make_tag_ref(tag)] = tag_id
示例#39
0
def tag_create(repo,
               tag,
               author=None,
               message=None,
               annotated=False,
               objectish="HEAD",
               tag_time=None,
               tag_timezone=None):
    """Creates a tag in git via dulwich calls:

    :param repo: Path to repository
    :param tag: tag string
    :param author: tag author (optional, if annotated is set)
    :param message: tag message (optional)
    :param annotated: whether to create an annotated tag
    :param objectish: object the tag should point at, defaults to HEAD
    :param tag_time: Optional time for annotated tag
    :param tag_timezone: Optional timezone for annotated tag
    """

    with open_repo_closing(repo) as r:
        object = parse_object(r, objectish)

        if annotated:
            # Create the tag object
            tag_obj = Tag()
            if author is None:
                # TODO(jelmer): Don't use repo private method.
                author = r._get_user_identity()
            tag_obj.tagger = author
            tag_obj.message = message
            tag_obj.name = tag
            tag_obj.object = (type(object), object.id)
            tag_obj.tag_time = tag_time
            if tag_time is None:
                tag_time = int(time.time())
            if tag_timezone is None:
                # TODO(jelmer) Use current user timezone rather than UTC
                tag_timezone = 0
            elif isinstance(tag_timezone, str):
                tag_timezone = parse_timezone(tag_timezone)
            tag_obj.tag_timezone = tag_timezone
            r.object_store.add_object(tag_obj)
            tag_id = tag_obj.id
        else:
            tag_id = object.id

        r.refs[b'refs/tags/' + tag] = tag_id
示例#40
0
文件: logsave.py 项目: ekeijl/BeAT
def create_log(repo, contents, filename, overwrite=False):
	"""creates a log with the specified content.
	This function creates a log file in the git repository specified by LOGS_PATH in settings.py.
	If a file with name filename exists, False is returned, unless overwrite=True.
	Arguments:
		contents		the contents of the log, as a simple string
		filename		the specific filename to use.
		overwrite		whether or not to overwrite existing files. defaults to False, does change behavior when filename=None.
	Returns:
		False on failure, the filename to which the log was saved on success.
	Raises:
		GitFileError	when the file exists while overwrite is False
	"""		
	if not filename:
		return "Error: empty filename"
	if not contents:
		return "Error: empty contents"
	if type(contents) is list:
		contents=''.join(contents)

	if path.exists(path.join(LOGS_PATH, filename)) and not overwrite:
		return "Error: file exists, overwrite not specified"


	#create file
	blob = Blob.from_string(contents)
	tree = get_latest_tree(repo)

	tree[filename]=(default_perms, blob.id)

	commit = Commit()
	commit.tree=tree.id
	commit.parents=[repo.head()]
	commit.author = commit.committer = "Logwriter [email protected]"
	commit.commit_time = commit.author_time = int(time())
	commit.commit_timezone = commit.author_timezone = parse_timezone('+0100')
	commit.encoding = "UTF-8"
	commit.message = "Writing log file %s"%(filename)
	
	store=repo.object_store
	store.add_object(blob)
	store.add_object(tree)
	store.add_object(commit)

	repo.refs['refs/heads/master'] = commit.id

	return True
示例#41
0
def make_commit(repo, tree, message, author, timezone, encoding="UTF-8"):
    """build a Commit object"""
    commit = Commit()
    try:
        commit.parents = [repo.head()]
    except KeyError:
        #the initial commit has no parent
        pass
    if isinstance(tree, dulwich.objects.Tree): tree_id = tree.id
    elif isinstance(tree, str): tree_id = tree
    commit.tree = tree_id
    commit.message = message
    commit.author = commit.committer = author
    commit.commit_time = commit.author_time = int(time())
    commit.commit_timezone = commit.author_timezone = parse_timezone(timezone)
    commit.encoding = encoding
    return commit
示例#42
0
def setup_app(command, conf, vars):
    """Place any commands to setup kekswiki here"""
    # Don't reload the app if it was loaded under the testing environment
    if not pylons.test.pylonsapp:
        load_environment(conf.global_conf, conf.local_conf)

    # create repository directory
    try:
        mkdir("wiki")
    except OSError:
        pass

    # create repository
    try:
        repo = Repo.init("wiki")
    except OSError:
        repo = Repo("wiki")

    # create blob
    blob = Blob.from_string("Kekswiki is a collaborative hypertext editing system.\n")

    # add blob to tree
    tree = Tree()
    tree.add(0100644, "Kekswiki", blob.id)

    # commit
    commit = Commit()
    commit.tree = tree.id
    author = "Anonymous <*****@*****.**>"
    commit.author = commit.committer = author
    commit.commit_time = commit.author_time = int(time())
    tz = parse_timezone('+0100')[0]  # FIXME: get proper timezone
    commit.commit_timezone = commit.author_timezone = tz
    commit.encoding = "UTF-8"
    commit.message = "Initial commit"

    # save everything
    object_store = repo.object_store
    object_store.add_object(blob)
    object_store.add_object(tree)
    object_store.add_object(commit)

    # create master branch, set it as current
    repo.refs.add_if_new('refs/heads/master', commit.id)
    repo.refs.set_symbolic_ref('HEAD', 'refs/heads/master')
示例#43
0
文件: db.py 项目: mbr/qwapp
	def reset_repo(self):
		# ensure head exists
			tree = Tree()

			commit = Commit()
			commit.tree = tree.id
			commit.author = commit.committer = self.wiki_user
			commit.commit_time = commit.author_time = int(time.time())
			commit.commit_timezone = commit.author_timezone = parse_timezone(time.timezone)[0]
			commit.encoding = 'UTF-8'
			commit.message = u'Automatic initalization by qwapp.'.encode('utf-8')

			# store all objects
			self.repo.object_store.add_object(tree)
			self.repo.object_store.add_object(commit)

			# update the branch
			self.repo.refs[self.head] = commit.id
示例#44
0
    def _dulwich_tag(self, tag, author, message=None):
        """ Creates a tag in git via dulwich calls:

                **tag** - string :: "<project>-[start|sync]-<timestamp>"
                **author** - string :: "Your Name <*****@*****.**>"
        """
        if not message:
            message = tag

        # Open the repo
        _repo = Repo(self.config['top_dir'])
        master_branch = 'master'

        # Build the commit object
        blob = Blob.from_string("empty")
        tree = Tree()
        tree.add(tag, 0100644, blob.id)

        commit = Commit()
        commit.tree = tree.id
        commit.author = commit.committer = author
        commit.commit_time = commit.author_time = int(time())
        tz = parse_timezone('-0200')[0]
        commit.commit_timezone = commit.author_timezone = tz
        commit.encoding = "UTF-8"
        commit.message = 'Tagging repo for deploy: ' + message

        # Add objects to the repo store instance
        object_store = _repo.object_store
        object_store.add_object(blob)
        object_store.add_object(tree)
        object_store.add_object(commit)
        _repo.refs['refs/heads/' + master_branch] = commit.id

        # Build the tag object and tag
        tag = Tag()
        tag.tagger = author
        tag.message = message
        tag.name = tag
        tag.object = (Commit, commit.id)
        tag.tag_time = commit.author_time
        tag.tag_timezone = tz
        object_store.add_object(tag)
        _repo['refs/tags/' + tag] = tag.id
示例#45
0
def tag_create(
    repo, tag, author=None, message=None, annotated=False, objectish="HEAD", tag_time=None, tag_timezone=None
):
    """Creates a tag in git via dulwich calls:

    :param repo: Path to repository
    :param tag: tag string
    :param author: tag author (optional, if annotated is set)
    :param message: tag message (optional)
    :param annotated: whether to create an annotated tag
    :param objectish: object the tag should point at, defaults to HEAD
    :param tag_time: Optional time for annotated tag
    :param tag_timezone: Optional timezone for annotated tag
    """

    with open_repo_closing(repo) as r:
        object = parse_object(r, objectish)

        if annotated:
            # Create the tag object
            tag_obj = Tag()
            if author is None:
                # TODO(jelmer): Don't use repo private method.
                author = r._get_user_identity()
            tag_obj.tagger = author
            tag_obj.message = message
            tag_obj.name = tag
            tag_obj.object = (type(object), object.id)
            tag_obj.tag_time = tag_time
            if tag_time is None:
                tag_time = int(time.time())
            if tag_timezone is None:
                # TODO(jelmer) Use current user timezone rather than UTC
                tag_timezone = 0
            elif isinstance(tag_timezone, str):
                tag_timezone = parse_timezone(tag_timezone)
            tag_obj.tag_timezone = tag_timezone
            r.object_store.add_object(tag_obj)
            tag_id = tag_obj.id
        else:
            tag_id = object.id

        r.refs[b"refs/tags/" + tag] = tag_id
示例#46
0
    def reset_repo(self):
        # ensure head exists
        tree = Tree()

        commit = Commit()
        commit.tree = tree.id
        commit.author = commit.committer = self.wiki_user
        commit.commit_time = commit.author_time = int(time.time())
        commit.commit_timezone = commit.author_timezone = parse_timezone(
            time.timezone)[0]
        commit.encoding = 'UTF-8'
        commit.message = u'Automatic initalization by qwapp.'.encode('utf-8')

        # store all objects
        self.repo.object_store.add_object(tree)
        self.repo.object_store.add_object(commit)

        # update the branch
        self.repo.refs[self.head] = commit.id
示例#47
0
def parse_reflog_line(line):
    """Parse a reflog line.

    Args:
      line: Line to parse
    Returns: Tuple of (old_sha, new_sha, committer, timestamp, timezone,
        message)
    """
    (begin, message) = line.split(b"\t", 1)
    (old_sha, new_sha, rest) = begin.split(b" ", 2)
    (committer, timestamp_str, timezone_str) = rest.rsplit(b" ", 2)
    return Entry(
        old_sha,
        new_sha,
        committer,
        int(timestamp_str),
        parse_timezone(timezone_str)[0],
        message,
    )
示例#48
0
 def _commit(self, tree):
     """
     commit a tree used only by the init
     ``tree``
         tree to commit
     """
     commit = Commit()
     commit.tree = tree.id
     commit.encoding = "UTF-8"
     commit.committer = commit.author = 'debexpo <%s>' % (pylons.config['debexpo.email'])
     commit.commit_time = commit.author_time = int(time())
     tz = parse_timezone('-0200')[0]
     commit.commit_timezone = commit.author_timezone = tz
     commit.message = " "
     self.repo.object_store.add_object(tree)
     self.repo.object_store.add_object(commit)
     self.repo.refs["HEAD"] = commit.id
     log.debug('commiting')
     return commit.id
示例#49
0
 def _commit(self, tree):
     """
     commit a tree used only by the init
     ``tree``
         tree to commit
     """
     commit = Commit()
     commit.tree = tree.id
     commit.encoding = "UTF-8"
     commit.committer = commit.author = 'debexpo <%s>' % (
         pylons.config['debexpo.email'])
     commit.commit_time = commit.author_time = int(time())
     tz = parse_timezone('-0200')[0]
     commit.commit_timezone = commit.author_timezone = tz
     commit.message = " "
     self.repo.object_store.add_object(tree)
     self.repo.object_store.add_object(commit)
     self.repo.refs["HEAD"] = commit.id
     log.debug('commiting')
     return commit.id
示例#50
0
    def new(self, repo):
        """
        Create a new version of a repo.Local object.

        :param repo: Instance of repo.Local.

        :return: New Version instance.
        """
        #TODO: subclass Commit, pass parent as init param
        try:
            # create new commit instance and set metadata
            commit = Commit()
            author = os.environ.get('USER')
            commit.author = commit.committer = author
            commit.commit_time = commit.author_time = int(time())
            tz = parse_timezone('-0200')[0]
            commit.commit_timezone = commit.author_timezone = tz
            commit.encoding = "UTF-8"
            commit.message = ''

            # set previous version as parent to this one
            parent = repo.versions(-1)
            if parent:
                commit.parents = [parent.id]

            # create new tree, add entries from previous version
            tree = Tree()
            curr = repo.versions(-1)
            if curr:
                for item in curr.items():
                    tree.addItem(item)
            commit.tree = tree.id

            # create new version, and add tree
            version = Version(repo=repo, commit=commit, tree=tree)
            return version

        except Exception, e:
            traceback.print_exc()
            return VersionError(e)
示例#51
0
def tag(repo, tag, author, message):
    """Creates a tag in git via dulwich calls:

    :param repo: Path to repository
    :param tag: tag string
    :param author: tag author
    :param repo: tag message
    """

    r = open_repo(repo)

    # Create the tag object
    tag_obj = Tag()
    tag_obj.tagger = author
    tag_obj.message = message
    tag_obj.name = tag
    tag_obj.object = (Commit, r.refs['HEAD'])
    tag_obj.tag_time = int(time.time())
    tag_obj.tag_timezone = parse_timezone('-0200')[0]

    # Add tag to the object store
    r.object_store.add_object(tag_obj)
    r.refs['refs/tags/' + tag] = tag_obj.id
示例#52
0
def tag(repo, tag, author, message):
    """Creates a tag in git via dulwich calls:

    :param repo: Path to repository
    :param tag: tag string
    :param author: tag author
    :param repo: tag message
    """

    r = open_repo(repo)

    # Create the tag object
    tag_obj = Tag()
    tag_obj.tagger = author
    tag_obj.message = message
    tag_obj.name = tag
    tag_obj.object = (Commit, r.refs['HEAD'])
    tag_obj.tag_time = int(time.time())
    tag_obj.tag_timezone = parse_timezone('-0200')[0]

    # Add tag to the object store
    r.object_store.add_object(tag_obj)
    r.refs['refs/tags/' + tag] = tag_obj.id
def step_impl_given(context):
    context.test_git_repo_dir = tempfile.mkdtemp('paasta_tools_deployments_json_itest')
    context.test_git_repo = Repo.init(context.test_git_repo_dir)
    print 'Temp repo in %s' % context.test_git_repo_dir

    blob = Blob.from_string("My file content\n")
    tree = Tree()
    tree.add("spam", 0100644, blob.id)

    commit = Commit()
    commit.author = commit.committer = "itest author"
    commit.commit_time = commit.author_time = int(time())
    commit.commit_timezone = commit.author_timezone = parse_timezone('-0200')[0]
    commit.message = "Initial commit"
    commit.tree = tree.id

    object_store = context.test_git_repo.object_store
    object_store.add_object(blob)
    object_store.add_object(tree)
    object_store.add_object(commit)

    context.test_git_repo.refs['refs/heads/paasta-test_cluster.test_instance'] = commit.id
    context.expected_commit = commit.id
示例#54
0
def step_impl_given(context):
    context.test_git_repo_dir = tempfile.mkdtemp("paasta_tools_deployments_json_itest")
    context.test_git_repo = Repo.init(context.test_git_repo_dir)
    paasta_print("Temp repo in %s" % context.test_git_repo_dir)

    blob = Blob.from_string(b"My file content\n")
    tree = Tree()
    tree.add(b"spam", 0100644, blob.id)

    commit = Commit()
    commit.author = commit.committer = b"itest author"
    commit.commit_time = commit.author_time = int(time())
    commit.commit_timezone = commit.author_timezone = parse_timezone("-0200")[0]
    commit.message = b"Initial commit"
    commit.tree = tree.id

    object_store = context.test_git_repo.object_store
    object_store.add_object(blob)
    object_store.add_object(tree)
    object_store.add_object(commit)

    context.test_git_repo.refs["refs/heads/master"] = commit.id
    context.expected_commit = commit.id
示例#55
0
def do_commit():
	global droid, localrepo, repo
	if localrepo==None:
		droid.makeToast("Set local repository first!")
	else:
 		object_store = repo.object_store
 		progress_to_log()
		if repo["refs/heads/master"] == None:
			tree = Tree()
		else:
			tree = object_store[repo["refs/heads/master"].tree]
		if do_tree_for_commit(tree):
			object_store.add_object(tree)
			commit = Commit()
			commit.tree = tree.id
			if repo.refs["refs/heads/master"] == None:
				commit.parents = []
				def_comment = "Initial commit"
			else:
				commit.parents = [repo.refs["refs/heads/master"]]
				def_comment = ""
			name = droid.fullQueryDetail("editName").result["text"]
			email = droid.fullQueryDetail("editEmail").result["text"]
			author = name + " <" + email + ">"
			commit.author = commit.committer = author
			commit.commit_time = commit.author_time = int(time())
			tz = parse_timezone('+0000')[0]
			commit.commit_timezone = commit.author_timezone = tz
			commit.encoding = "UTF-8"
			commit.message = showinput("Message", "Enter commit message", def_comment)
			if commit.message:
				object_store.add_object(commit)
				repo.refs['refs/heads/master'] = commit.id
			else:
				droid.makeToast("Commit cancelled.")
 		else:
 			droid.makeToast("Nothing to commit.")
示例#56
0
    def _update_file(self, name, subdir, filename, data, commit_msg):
        # first, create a new blob for the data
        blob = Blob.from_string(data.encode('utf-8'))

        # fetch the old tree object, add new page
        try:
            subdir_tree = _walk_git_repo_tree(self.repo, self.current_tree,
                                              subdir)
        except KeyError:
            # we need to create the subdir_tree as well, since it does not exist
            # yet
            subdir_tree = Tree()
        subdir_tree.add(_git_default_file_mode, filename, blob.id)

        # create new root tree
        tree = self.current_tree
        tree.add(stat.S_IFDIR, subdir, subdir_tree.id)

        # create commit
        commit = Commit()
        commit.parents = [self.current_commit.id]
        commit.tree = tree.id
        commit.author = commit.committer = self.wiki_user
        commit.commit_time = commit.author_time = int(time.time())
        commit.commit_timezone = commit.author_timezone = parse_timezone(
            time.timezone)[0]
        commit.encoding = 'UTF-8'
        commit.message = commit_msg.encode('utf-8')

        # store all objects
        self.repo.object_store.add_object(blob)
        self.repo.object_store.add_object(subdir_tree)
        self.repo.object_store.add_object(tree)
        self.repo.object_store.add_object(commit)

        # update the branch
        self.repo.refs[self.head] = commit.id
示例#57
0
 def test_parse_timezone_pdt_half(self):
     self.assertEqual((((-4 * 60) - 40) * 60, False),
         parse_timezone("-0440"))
示例#58
0
 def test_parse_timezone_pdt(self):
     self.assertEqual((-4 * 60 * 60, False), parse_timezone("-0400"))
示例#59
0
 def test_parse_timezone_double_negative(self):
     self.assertEqual(
         (int(((7 * 60)) * 60), False), parse_timezone("+700"))
     self.assertEqual(
         (int(((7 * 60)) * 60), True), parse_timezone("--700"))