Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
AJMansfield opened this issue Jul 19, 2017 · 3 comments
Closed

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

AJMansfield opened this issue Jul 19, 2017 · 3 comments

Comments

@AJMansfield
Copy link
Contributor

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':'[email protected]',
	'GIT_AUTHOR_DATE':'1400000000+0000',
	'GIT_COMMITTER_NAME':'Comitter Name',
	'GIT_COMMITTER_EMAIL':'[email protected]',
	'GIT_COMMITTER_DATE':'1500000000+0000',
	})
@AJMansfield
Copy link
Contributor Author

Note that I'm currently working on a fix (https://github.com/AJMansfield/GitPython), just wanted to document the issue first.

@bpoldrack
Copy link
Contributor

Isn't that, what with custom_environment( ....) is for?

@AJMansfield
Copy link
Contributor Author

@bpoldrack Two reasons, one technical and the other semantic.

  • with custom_environment( ... ) isn't thread-safe. I'm using this in a threaded context, and having to manage creating separate Git instances per-thread adds extra complexity.

  • It's not really the 'right' way to do it in my use case, as the author and committer data are genuinely parameters rather than configuration information for my use case - I'm copying existing information from another VCS over to git, not creating new info.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants