Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7c770a5

Browse files
author
Tom Daniels
committed
adding Repo wrapping class WildRepo that allows for easier manipulation of wild repos.
1 parent 0b820e6 commit 7c770a5

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

git/repo/base.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import os
3939
import sys
4040
import re
41+
from shutil import copy2, rmtree # for WildRepo
4142

4243
DefaultDBType = GitDB
4344
if sys.version_info[1] < 5: # python 2.4 compatiblity
@@ -766,3 +767,44 @@ def archive(self, ostream, treeish=None, prefix=None, **kwargs):
766767

767768
def __repr__(self):
768769
return '<git.Repo "%s">' % self.git_dir
770+
771+
class WildRepo(Repo):
772+
"""
773+
WildRepo is an extension of the GitPython Repo class. It extends the
774+
functionality to allow for dynamic repo configurations (e.g., repo
775+
templates with std files and/or git hooks) in 'wild repos'; dynamically
776+
created gitolite repos.
777+
"""
778+
def __init__(self, path=None):
779+
super(WildRepo, self).__init__(path)
780+
781+
def add(self, path):
782+
"""
783+
Extends Repo.index.add by removing the requirement that the file to be
784+
added is already in the working directory. Instead it accepts a path
785+
and will make a copy of the file within the repository and then add
786+
it.
787+
"""
788+
copy2(path, self.working_dir)
789+
name = os.path.basename(path)
790+
return self.index.add(items={name})
791+
792+
def commit(self, message=None):
793+
"""
794+
A wrapper around Repo.index.commit. Doesn't currently add any
795+
additional functionality.
796+
"""
797+
if message is not None:
798+
return self.index.commit(message)
799+
else:
800+
return ValueError("Commit message can not be None.")
801+
802+
def add_hook(self, path, hook):
803+
"""
804+
Allows dynamic addition of Git hooks to wild repositories when they
805+
are created. The path to the hook is provided and it is symlinked into
806+
%working_dir%/hooks/.
807+
"""
808+
hooks_path = "%s/hooks/%s" % (self.working_dir, hook)
809+
os.symlink(path, hooks_path)
810+

0 commit comments

Comments
 (0)