forked from gil9red/SimplePyScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclone_and_pull.py
More file actions
39 lines (27 loc) · 861 Bytes
/
Copy pathclone_and_pull.py
File metadata and controls
39 lines (27 loc) · 861 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
__author__ = 'ipetrash'
url = 'https://github.com/gil9red/search_in_users_github_gists.git'
# Если закончивается url на .git
len_url = len(url)
if '.git' == url[len_url - 4: len_url]:
url = url[:len_url - 4]
import os
rw_dir = 'my_git_repos'
path = os.path.join(rw_dir, url.split('/')[-1])
# pip install gitpython
import git
if os.path.exists(path):
repo = git.Repo(path)
else:
repo = git.Repo.clone_from(url, path, branch='master')
# blast any current changes
repo.git.reset('--hard')
# ensure master is checked out
repo.heads.master.checkout()
# blast any changes there (only if it wasn't checked out)
repo.git.reset('--hard')
# remove any extra non-tracked files (.pyc, etc)
repo.git.clean('-xdf')
# pull in the changes from from the remote
repo.remotes.origin.pull()