blob: 1ff858804c57247d386a4139559c691f6c07714b [file] [log] [blame]
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -07001#
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
16import sys
17
18from color import Coloring
19from command import InteractiveCommand
20from git_command import GitCommand
21
22class _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
29class Stage(InteractiveCommand):
30 common = True
31 helpSummary = "Stage file(s) for commit"
32 helpUsage = """
33%prog -i [<project>...]
34"""
35 helpDescription = """
36The '%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):
David Pursehouse8a68ff92012-09-24 12:15:13 +090051 all_projects = filter(lambda x: x.IsDirty(), self.GetProjects(args))
52 if not all_projects:
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -070053 print >>sys.stderr,'no projects have uncommitted modifications'
54 return
55
56 out = _ProjectList(self.manifest.manifestProject.config)
57 while True:
Shawn O. Pearcedeec0532009-04-18 11:22:13 -070058 out.header(' %s', 'project')
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -070059 out.nl()
60
Sarah Owensa6053d52012-11-01 13:36:50 -070061 for i in range(len(all_projects)):
David Pursehouse8a68ff92012-09-24 12:15:13 +090062 p = all_projects[i]
Shawn O. Pearcedeec0532009-04-18 11:22:13 -070063 out.write('%3d: %s', i + 1, p.relpath + '/')
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -070064 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
David Pursehouse8a68ff92012-09-24 12:15:13 +090096 if 0 < a_index and a_index <= len(all_projects):
97 _AddI(all_projects[a_index - 1])
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -070098 continue
99
David Pursehouse8a68ff92012-09-24 12:15:13 +0900100 p = filter(lambda x: x.name == a or x.relpath == a, all_projects)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700101 if len(p) == 1:
102 _AddI(p[0])
103 continue
104 print 'Bye.'
105
106def _AddI(project):
107 p = GitCommand(project, ['add', '--interactive'], bare=False)
108 p.Wait()