1
0
mirror of https://gitlab.com/fdroid/fdroidserver.git synced 2024-11-09 00:40:11 +01:00

Guard against git accidents

This commit is contained in:
Ciaran Gultnieks 2012-01-08 13:43:59 +00:00
parent 856eab7393
commit cabd2c5522

View File

@ -85,11 +85,19 @@ class vcs:
class vcs_git(vcs): class vcs_git(vcs):
def checkrepo(self):
p = subprocess.Popen('git', 'rev-parse', '--show-toplevel',
stdout=subprocess.PIPE)
result = p.communicate()[0].rstrip()
if not self.local.endswith(result):
raise VCSException('Repository mismatch')
def clone(self): def clone(self):
if subprocess.call(['git', 'clone', self.remote, self.local]) != 0: if subprocess.call(['git', 'clone', self.remote, self.local]) != 0:
raise VCSException("Git clone failed") raise VCSException("Git clone failed")
def reset(self, rev=None): def reset(self, rev=None):
self.checkrepo()
if rev is None: if rev is None:
rev = 'origin' rev = 'origin'
if subprocess.call(['git', 'reset', '--hard', rev], if subprocess.call(['git', 'reset', '--hard', rev],
@ -100,6 +108,7 @@ class vcs_git(vcs):
raise VCSException("Git clean failed") raise VCSException("Git clean failed")
def pull(self): def pull(self):
self.checkrepo()
if subprocess.call(['git', 'pull', 'origin'], if subprocess.call(['git', 'pull', 'origin'],
cwd=self.local) != 0: cwd=self.local) != 0:
raise VCSException("Git pull failed") raise VCSException("Git pull failed")
@ -109,6 +118,7 @@ class vcs_git(vcs):
raise VCSException("Git fetch failed") raise VCSException("Git fetch failed")
def initsubmodules(self): def initsubmodules(self):
self.checkrepo()
if subprocess.call(['git', 'submodule', 'init'], if subprocess.call(['git', 'submodule', 'init'],
cwd=self.local) != 0: cwd=self.local) != 0:
raise VCSException("Git submodule init failed") raise VCSException("Git submodule init failed")
@ -119,11 +129,19 @@ class vcs_git(vcs):
class vcs_gitsvn(vcs): class vcs_gitsvn(vcs):
def checkrepo(self):
p = subprocess.Popen('git', 'rev-parse', '--show-toplevel',
stdout=subprocess.PIPE)
result = p.communicate()[0].rstrip()
if not self.local.endswith(result):
raise VCSException('Repository mismatch')
def clone(self): def clone(self):
if subprocess.call(['git', 'svn', 'clone', self.remote, self.local]) != 0: if subprocess.call(['git', 'svn', 'clone', self.remote, self.local]) != 0:
raise VCSException("Git clone failed") raise VCSException("Git clone failed")
def reset(self, rev=None): def reset(self, rev=None):
self.checkrepo()
if rev is None: if rev is None:
rev = 'HEAD' rev = 'HEAD'
else: else:
@ -140,6 +158,7 @@ class vcs_gitsvn(vcs):
raise VCSException("Git clean failed") raise VCSException("Git clean failed")
def pull(self): def pull(self):
self.checkrepo()
if subprocess.call(['git', 'svn', 'rebase'], if subprocess.call(['git', 'svn', 'rebase'],
cwd=self.local) != 0: cwd=self.local) != 0:
raise VCSException("Git svn rebase failed") raise VCSException("Git svn rebase failed")