forked from Nginlion/git-in-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommand.py
More file actions
96 lines (76 loc) · 2.26 KB
/
command.py
File metadata and controls
96 lines (76 loc) · 2.26 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
'''
Created on Jun 9, 2014
@author: lzrak47
'''
import os
from termcolor import colored
from branch import Branch
from constants import GIT_DIR
from repository import Repository
from utils import get_all_files_in_dir, filter_by_gitignore
class Command(object):
'''
handle all commands
'''
@staticmethod
def cmd_init(workspace, bare):
Repository.create_repository(workspace, bare)
@staticmethod
def cmd_add(file):
if file == '.':
Repository().stage(filter_by_gitignore(get_all_files_in_dir('.', GIT_DIR)))
else:
Repository().stage([file])
@staticmethod
def cmd_rm(file, cached):
Repository().delete(file)
if not cached:
os.remove(file)
@staticmethod
def cmd_commit(msg):
Repository().commit(msg)
@staticmethod
def cmd_log(num):
Repository().show_log(num)
@staticmethod
def cmd_status():
Repository().show_status()
@staticmethod
def cmd_branch(name, is_deleted):
b = Branch()
if not name:
for branch in b.get_all_branches():
print '* %s' % colored(branch, 'green') if branch == b.head_name else ' %s' % branch
elif is_deleted:
b.delete_branch(name)
else :
b.add_branch(name)
@staticmethod
def cmd_reset(commit_sha1, is_soft, is_hard):
repo = Repository()
pre_entries = dict(repo.index.entries)
repo.update_head_commit(commit_sha1)
if not is_soft:
repo.rebuild_index_from_commit(commit_sha1)
if is_hard:
repo.rebuild_working_tree(pre_entries)
@staticmethod
def cmd_checkout(branch):
b = Branch()
b.switch_branch(branch)
repo = Repository()
pre_entries = dict(repo.index.entries)
repo.rebuild_index_from_commit(repo.branch.head_commit)
repo.rebuild_working_tree(pre_entries)
@staticmethod
def cmd_diff(cached):
if cached:
Repository().diff_between_index_and_head_tree()
else:
Repository().diff_between_working_tree_and_index()
@staticmethod
def cmd_push():
pass
@staticmethod
def cmd_clone():
pass