mirror of
https://github.com/ejwa/gitinspector.git
synced 2025-03-19 23:08:15 +01:00
Implemented support for remote repositories (Fixes issue 18).
The supported protocols are file://, git://, http://, https:// and ssh://. Whenever one of the above prefixes are detected in the repository name, "git clone" is used to clone the repository into a temporary directory. When "git clone" is called, it's output is redirected to stderr; meaning that redirection of stdout to a file functions just as before. If "git clone" fails for some reason, gitinspector will exit; returning the error code from the "git clone" command.
This commit is contained in:
parent
974be06f2b
commit
a45df61aa9
2 changed files with 58 additions and 0 deletions
gitinspector
49
gitinspector/clone.py
Normal file
49
gitinspector/clone.py
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
# coding: utf-8
|
||||||
|
#
|
||||||
|
# Copyright © 2014 Ejwa Software. All rights reserved.
|
||||||
|
#
|
||||||
|
# This file is part of gitinspector.
|
||||||
|
#
|
||||||
|
# gitinspector is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# gitinspector is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with gitinspector. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
import shutil
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
import tempfile
|
||||||
|
|
||||||
|
__cloned_path__ = None
|
||||||
|
|
||||||
|
def create(url):
|
||||||
|
if url.startswith("file://") or url.startswith("git://") or url.startswith("http://") or \
|
||||||
|
url.startswith("https://") or url.startswith("ssh://"):
|
||||||
|
global __cloned_path__
|
||||||
|
|
||||||
|
location = tempfile.mkdtemp(suffix=".gitinspector")
|
||||||
|
git_clone = subprocess.Popen("git clone {0} {1}".format(url, location), shell=True, bufsize=1, stdout=sys.stderr)
|
||||||
|
git_clone.wait()
|
||||||
|
|
||||||
|
if git_clone.returncode != 0:
|
||||||
|
sys.exit(git_clone.returncode)
|
||||||
|
|
||||||
|
__cloned_path__ = location
|
||||||
|
return location
|
||||||
|
return url
|
||||||
|
|
||||||
|
def delete():
|
||||||
|
global __cloned_path__
|
||||||
|
|
||||||
|
if __cloned_path__:
|
||||||
|
shutil.rmtree(__cloned_path__, ignore_errors=True)
|
|
@ -24,8 +24,10 @@ from __future__ import unicode_literals
|
||||||
import localization
|
import localization
|
||||||
localization.init()
|
localization.init()
|
||||||
|
|
||||||
|
import atexit
|
||||||
import blame
|
import blame
|
||||||
import changes
|
import changes
|
||||||
|
import clone
|
||||||
import config
|
import config
|
||||||
import extensions
|
import extensions
|
||||||
import filtering
|
import filtering
|
||||||
|
@ -127,6 +129,9 @@ def main():
|
||||||
for arg in __args__:
|
for arg in __args__:
|
||||||
__run__.repo = arg
|
__run__.repo = arg
|
||||||
|
|
||||||
|
#Try to clone the repo or return the same directory and bail out.
|
||||||
|
__run__.repo = clone.create(__run__.repo)
|
||||||
|
|
||||||
#We need the repo above to be set before we read the git config.
|
#We need the repo above to be set before we read the git config.
|
||||||
config.init(__run__)
|
config.init(__run__)
|
||||||
clear_x_on_next_pass = True
|
clear_x_on_next_pass = True
|
||||||
|
@ -198,5 +203,9 @@ def main():
|
||||||
print(_("Try `{0} --help' for more information.").format(sys.argv[0]), file=sys.stderr)
|
print(_("Try `{0} --help' for more information.").format(sys.argv[0]), file=sys.stderr)
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
|
|
||||||
|
@atexit.register
|
||||||
|
def cleanup():
|
||||||
|
clone.delete()
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
Loading…
Add table
Reference in a new issue