Closed
Description
In the following code you are not able to supply what paths you would like to archive (and not all the repo).
repo = git.Repo("/git/repo")
repo.archive(ostream=temparchive, treeish="master", format="tar")
Meanwhile, if you use the git archive command you can suplly what paths you would like to archive.
An extra kw args could be the list of paths you want in the tar file.
Metadata
Metadata
Assignees
Type
Projects
Relationships
Development
No branches or pull requests
Activity
nuarhu commentedon Jul 10, 2012
Me too...!
I've tried setting the "working_dir" but it's not used for the archive call - although this is what "git archive" actually does: if you are in a subdirectory, it will only archive the subdirectory's contents (recursively).
I have difficulties finding the "archive" method in the current master. Code search on github only produced a hit on GitPython / lib / git / repo.py (tree: 90d73cd): https://github.com/search?q=repo%3Agitpython-developers%2FGitPython+archive&repo=&langOverride=&start_value=1&type=Everything&language=
(I'm feeling like I'm missing the obvious...)
maurociancio commentedon Jul 10, 2012
Yes, I've dug into the code but I couldn't find the appropiate place to add the neeeded argument. Maybe someone else with more understanding of the code base could throw us some pointers.
What I've found is the following, but I know itsn't enough :P:
git grep -n "archive("
git/db/cmd/base.py:847: def archive(self, ostream, treeish=None, prefix=None, *_kwargs):
git/db/cmd/base.py:861: self.git.archive(treeish, *_kwargs)
git/db/interface.py:824: def archive(self, ostream, treeish=None, prefix=None):
Any ideas?
Byron commentedon Jul 11, 2012
Sorry for the late reply.
Looking in master is not actually recommended, as the code is bleeding edge and is not even alpha.
In 0.3, what you could try instead is to just use the git command directly, maybe the following snipped helps:
You can rather easily create fancy command invocations using the git command wrapper - this way you can do everything that you can do with the commandline.
In 0.3, the cmd.py module would be the place to look for more information.
If you ask me, repo.archive isn't really required as the same call can be made much easier using the git command itself - it was in the interface since 0.17 though and could be considered legacy.
Good luck !
nuarhu commentedon Jul 12, 2012
Hi Byron,
thank you for your reply which is not late at all!
I've (sheepishly) tried your code without modification and this gives me:
(changed path value and added line break for readability)
UPDATE:
To hand over a value without option like in
something like:
seems to be the way to go? However, it returns an error which includes a git call which - when pasted into the commandline - dumps the tar stream to stdout = does what I want. So, either the command which is output by GitCommandError is not the one actually called or something else goes wrong on the way.
(path changed)
Command line:
dumps the tar output.
nuarhu commentedon Jul 12, 2012
This actually works (work around): changing the working directory and changing back afterwards.
Note that the first line has no effect!
The work around consists of the call "os.chdir" in combination with the "with_keep_cwd=True" argument to the gitrepo.archive command call.
maurociancio commentedon Sep 24, 2012
Hello all,
I recently found out that executing "git archive master:folder" creates an archive that only contains the 'folder' directory.
I tested the command using GitPython and it works great.
So, there is no need to hack the source code or to change the current directory as @nuarhu suggested.
This works out of the box ;)
Well done git, well done :)
vishakhamudgal commentedon Dec 21, 2012
does archiving supported by github?
Byron commentedon Jan 14, 2015
You can now watch the live-coding session on youtube.