diff --git a/README.rst b/README.rst index 6178770..9bca125 100644 --- a/README.rst +++ b/README.rst @@ -13,6 +13,8 @@ Usage:: {repository,sshkey} The main command repository Manage your repository sshkey Manage your sshkey + clone Clone your repository + push Add, commit and push to your repository optional arguments: -h, --help show this help message and exit @@ -51,6 +53,20 @@ SSHKey :: optional arguments: -h, --help show this help message and exit +Clone :: + + usage: blih clone ... + + positional arguments: + Name of your repository + +Push :: + + usage: blih push ... + + positional arguments: + Message of your commit + .. |build-status| image:: https://circleci.com/gh/bocal/blih.svg?&style=shield :target: https://circleci.com/gh/bocal/blih diff --git a/blih/__init__.py b/blih/__init__.py index 189e0c5..f2bbcfc 100755 --- a/blih/__init__.py +++ b/blih/__init__.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # -*- coding: utf-8 -*- #- @@ -34,6 +34,7 @@ import sys import os +import git from argparse import ArgumentParser import getpass @@ -230,6 +231,31 @@ def sshkey_delete(user, password, comment, **kwargs): return {'data' : data, 'format' : ''} +# pylint: disable=unused-argument +def clone_from_repository(user, password, name, **kwargs): + """ + Git clone from repository + """ + g = git.cmd.Git(os.getcwd()) + git_url = 'git@git.epitech.eu:/' + user + '/' + name + g.clone(git_url) + +#pylink: disable=unused-argument +def push_to_repository(user, password, message, **kwargs): + """ + Git add, commit and push to repository + """ + repo = git.Repo(os.getcwd()) + # files = repo.git.diff(None, name_only=True) + # for f in files.split('\n'): + # show_diff(f) + # repo.git.add(f) + repo.git.add(A=True) + + repo.git.commit('-m', message) + repo.git.push('origin', 'master') + + #pylint: disable=R0914,too-many-statements def main(): """ @@ -283,7 +309,7 @@ def main(): ) parser_repo_info.add_argument('name', help='The repository name') parser_repo_info.set_defaults(func=repository_info) - + parser_repo_list = subparser_repository.add_parser( 'list', help='Get the list of your repositories' @@ -348,6 +374,22 @@ def main(): parser_sshkey_delete.add_argument('comment', help='The comment of the sshkey file to delete') parser_sshkey_delete.set_defaults(func=sshkey_delete) + # Git functionality in BLIH + + parser_clone = subparser.add_parser( + 'clone', + help='Use git clone' + ) + parser_clone.add_argument('name', help='The repository name') + parser_clone.set_defaults(func=clone_from_repository) + + parser_push = subparser.add_parser( + 'push', + help='Use git push' + ) + parser_push.add_argument('message', help='Commit message') + parser_push.set_defaults(func=push_to_repository) + argument = parser.parse_args() if argument.password == None: diff --git a/blih/__init__.pyc b/blih/__init__.pyc new file mode 100644 index 0000000..1f7e4eb Binary files /dev/null and b/blih/__init__.pyc differ