You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Archive method does not support paths parameter #67
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.
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).
gitrepo.working_dir = subdirectory
print "DEBUG: archive working dir is %s" % gitrepo.working_dir
## outputs the value of "subdirectory" but this is not used in a subsequent gitrepo.archive call
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:
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:
# resolves to git-archive --option-arg --value-arg "value"repo.git.archive(option_arg=True, value_arg="value")
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.
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.
File "./gitrex.py", line 153, in git_archive
gitrepo.archive(open(desttar,'wb'), [('', rev), ('', working_dir)])
File "/Library/Python/2.7/site-packages/GitPython-0.3.2.RC1-py2.7.egg/git/repo/base.py", line 759, in archive
self.git.archive(treeish, **kwargs)
File "/Library/Python/2.7/site-packages/GitPython-0.3.2.RC1-py2.7.egg/git/cmd.py", line 227, in <lambda>
return lambda *args, **kwargs: self._call_process(name, *args, **kwargs)
File "/Library/Python/2.7/site-packages/GitPython-0.3.2.RC1-py2.7.egg/git/cmd.py", line 456, in _call_process
return self.execute(call, **_kwargs)
File "/Library/Python/2.7/site-packages/GitPython-0.3.2.RC1-py2.7.egg/git/cmd.py", line 377, in execute
raise GitCommandError(command, status, stderr_value)
git.exc.GitCommandError: 'git archive HEAD /absolute/working/dir' returned exit status 128: fatal: Not a valid object name
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 ;)
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): http://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.
Merge pull request gitpython-developers#67 from gitpython-developers/…