Skip to content

Can't pass environment variables to Git.execute #644

Description

@AJMansfield

This is needed for commands like git-commit and git-commit-tree in order to be able to specify author and committer information. While git-commit does provide the --author and --date to specify author information, there are no options for specifying committer information, and git-commit-tree is wholly dependent on environment variables.

For instance, the following code fails with TypeError: type object got multiple values for keyword argument 'env'.

def pipe_of(string):
	import os
	if type(string) is str:
		string = bytes(string, 'utf-8')
	r,w = os.pipe()
	os.write(w, string)
	os.close(w)
	return r
git = Repo('/path/ro/repo').git
blob = git.execute(['git', 'hash-object', '-w', '--stdin'], istream=pipe_of("my data"))
tree = git.execute(['git', 'mktree'], istream=pipe_of("100644 blob {}\tmy-file\n".format(blob)))
commit = git.execute(['git', 'commit-tree', tree], istream=None, env={
	'GIT_AUTHOR_NAME':'Author Name',
	'GIT_AUTHOR_EMAIL':'author@example.com',
	'GIT_AUTHOR_DATE':'1400000000+0000',
	'GIT_COMMITTER_NAME':'Comitter Name',
	'GIT_COMMITTER_EMAIL':'committer@example.com',
	'GIT_COMMITTER_DATE':'1500000000+0000',
	})

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions