diff options
author | The Android Open Source Project <initial-contribution@android.com> | 2008-10-21 07:00:00 -0700 |
---|---|---|
committer | The Android Open Source Project <initial-contribution@android.com> | 2008-10-21 07:00:00 -0700 |
commit | cf31fe9b4fb650b27e19f5d7ee7297e383660caf (patch) | |
tree | d04ca6a45d579dca5e5469606c48c405aee68f4b /subcmds/stage.py | |
download | git-repo-cf31fe9b4fb650b27e19f5d7ee7297e383660caf.tar.gz |
Initial Contributionv1.0
Diffstat (limited to 'subcmds/stage.py')
-rw-r--r-- | subcmds/stage.py | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/subcmds/stage.py b/subcmds/stage.py new file mode 100644 index 00000000..c451cd6d --- /dev/null +++ b/subcmds/stage.py | |||
@@ -0,0 +1,108 @@ | |||
1 | # | ||
2 | # Copyright (C) 2008 The Android Open Source Project | ||
3 | # | ||
4 | # Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | # you may not use this file except in compliance with the License. | ||
6 | # You may obtain a copy of the License at | ||
7 | # | ||
8 | # http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | # | ||
10 | # Unless required by applicable law or agreed to in writing, software | ||
11 | # distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | # See the License for the specific language governing permissions and | ||
14 | # limitations under the License. | ||
15 | |||
16 | import sys | ||
17 | |||
18 | from color import Coloring | ||
19 | from command import InteractiveCommand | ||
20 | from git_command import GitCommand | ||
21 | |||
22 | class _ProjectList(Coloring): | ||
23 | def __init__(self, gc): | ||
24 | Coloring.__init__(self, gc, 'interactive') | ||
25 | self.prompt = self.printer('prompt', fg='blue', attr='bold') | ||
26 | self.header = self.printer('header', attr='bold') | ||
27 | self.help = self.printer('help', fg='red', attr='bold') | ||
28 | |||
29 | class Stage(InteractiveCommand): | ||
30 | common = True | ||
31 | helpSummary = "Stage file(s) for commit" | ||
32 | helpUsage = """ | ||
33 | %prog -i [<project>...] | ||
34 | """ | ||
35 | helpDescription = """ | ||
36 | The '%prog' command stages files to prepare the next commit. | ||
37 | """ | ||
38 | |||
39 | def _Options(self, p): | ||
40 | p.add_option('-i', '--interactive', | ||
41 | dest='interactive', action='store_true', | ||
42 | help='use interactive staging') | ||
43 | |||
44 | def Execute(self, opt, args): | ||
45 | if opt.interactive: | ||
46 | self._Interactive(opt, args) | ||
47 | else: | ||
48 | self.Usage() | ||
49 | |||
50 | def _Interactive(self, opt, args): | ||
51 | all = filter(lambda x: x.IsDirty(), self.GetProjects(args)) | ||
52 | if not all: | ||
53 | print >>sys.stderr,'no projects have uncommitted modifications' | ||
54 | return | ||
55 | |||
56 | out = _ProjectList(self.manifest.manifestProject.config) | ||
57 | while True: | ||
58 | out.header(' %-20s %s', 'project', 'path') | ||
59 | out.nl() | ||
60 | |||
61 | for i in xrange(0, len(all)): | ||
62 | p = all[i] | ||
63 | out.write('%3d: %-20s %s', i + 1, p.name, p.relpath + '/') | ||
64 | out.nl() | ||
65 | out.nl() | ||
66 | |||
67 | out.write('%3d: (', 0) | ||
68 | out.prompt('q') | ||
69 | out.write('uit)') | ||
70 | out.nl() | ||
71 | |||
72 | out.prompt('project> ') | ||
73 | try: | ||
74 | a = sys.stdin.readline() | ||
75 | except KeyboardInterrupt: | ||
76 | out.nl() | ||
77 | break | ||
78 | if a == '': | ||
79 | out.nl() | ||
80 | break | ||
81 | |||
82 | a = a.strip() | ||
83 | if a.lower() in ('q', 'quit', 'exit'): | ||
84 | break | ||
85 | if not a: | ||
86 | continue | ||
87 | |||
88 | try: | ||
89 | a_index = int(a) | ||
90 | except ValueError: | ||
91 | a_index = None | ||
92 | |||
93 | if a_index is not None: | ||
94 | if a_index == 0: | ||
95 | break | ||
96 | if 0 < a_index and a_index <= len(all): | ||
97 | _AddI(all[a_index - 1]) | ||
98 | continue | ||
99 | |||
100 | p = filter(lambda x: x.name == a or x.relpath == a, all) | ||
101 | if len(p) == 1: | ||
102 | _AddI(p[0]) | ||
103 | continue | ||
104 | print 'Bye.' | ||
105 | |||
106 | def _AddI(project): | ||
107 | p = GitCommand(project, ['add', '--interactive'], bare=False) | ||
108 | p.Wait() | ||