diff options
Diffstat (limited to 'subcmds/stage.py')
-rw-r--r-- | subcmds/stage.py | 181 |
1 files changed, 97 insertions, 84 deletions
diff --git a/subcmds/stage.py b/subcmds/stage.py index bdb72012..4d54eb19 100644 --- a/subcmds/stage.py +++ b/subcmds/stage.py | |||
@@ -20,98 +20,111 @@ from git_command import GitCommand | |||
20 | 20 | ||
21 | 21 | ||
22 | class _ProjectList(Coloring): | 22 | class _ProjectList(Coloring): |
23 | def __init__(self, gc): | 23 | def __init__(self, gc): |
24 | Coloring.__init__(self, gc, 'interactive') | 24 | Coloring.__init__(self, gc, "interactive") |
25 | self.prompt = self.printer('prompt', fg='blue', attr='bold') | 25 | self.prompt = self.printer("prompt", fg="blue", attr="bold") |
26 | self.header = self.printer('header', attr='bold') | 26 | self.header = self.printer("header", attr="bold") |
27 | self.help = self.printer('help', fg='red', attr='bold') | 27 | self.help = self.printer("help", fg="red", attr="bold") |
28 | 28 | ||
29 | 29 | ||
30 | class Stage(InteractiveCommand): | 30 | class Stage(InteractiveCommand): |
31 | COMMON = True | 31 | COMMON = True |
32 | helpSummary = "Stage file(s) for commit" | 32 | helpSummary = "Stage file(s) for commit" |
33 | helpUsage = """ | 33 | helpUsage = """ |
34 | %prog -i [<project>...] | 34 | %prog -i [<project>...] |
35 | """ | 35 | """ |
36 | helpDescription = """ | 36 | helpDescription = """ |
37 | The '%prog' command stages files to prepare the next commit. | 37 | The '%prog' command stages files to prepare the next commit. |
38 | """ | 38 | """ |
39 | 39 | ||
40 | def _Options(self, p): | 40 | def _Options(self, p): |
41 | g = p.get_option_group('--quiet') | 41 | g = p.get_option_group("--quiet") |
42 | g.add_option('-i', '--interactive', | 42 | g.add_option( |
43 | dest='interactive', action='store_true', | 43 | "-i", |
44 | help='use interactive staging') | 44 | "--interactive", |
45 | 45 | dest="interactive", | |
46 | def Execute(self, opt, args): | 46 | action="store_true", |
47 | if opt.interactive: | 47 | help="use interactive staging", |
48 | self._Interactive(opt, args) | 48 | ) |
49 | else: | 49 | |
50 | self.Usage() | 50 | def Execute(self, opt, args): |
51 | 51 | if opt.interactive: | |
52 | def _Interactive(self, opt, args): | 52 | self._Interactive(opt, args) |
53 | all_projects = [ | 53 | else: |
54 | p for p in self.GetProjects(args, all_manifests=not opt.this_manifest_only) | 54 | self.Usage() |
55 | if p.IsDirty()] | 55 | |
56 | if not all_projects: | 56 | def _Interactive(self, opt, args): |
57 | print('no projects have uncommitted modifications', file=sys.stderr) | 57 | all_projects = [ |
58 | return | 58 | p |
59 | 59 | for p in self.GetProjects( | |
60 | out = _ProjectList(self.manifest.manifestProject.config) | 60 | args, all_manifests=not opt.this_manifest_only |
61 | while True: | 61 | ) |
62 | out.header(' %s', 'project') | 62 | if p.IsDirty() |
63 | out.nl() | 63 | ] |
64 | 64 | if not all_projects: | |
65 | for i in range(len(all_projects)): | 65 | print("no projects have uncommitted modifications", file=sys.stderr) |
66 | project = all_projects[i] | 66 | return |
67 | out.write('%3d: %s', i + 1, | 67 | |
68 | project.RelPath(local=opt.this_manifest_only) + '/') | 68 | out = _ProjectList(self.manifest.manifestProject.config) |
69 | out.nl() | 69 | while True: |
70 | out.nl() | 70 | out.header(" %s", "project") |
71 | 71 | out.nl() | |
72 | out.write('%3d: (', 0) | 72 | |
73 | out.prompt('q') | 73 | for i in range(len(all_projects)): |
74 | out.write('uit)') | 74 | project = all_projects[i] |
75 | out.nl() | 75 | out.write( |
76 | 76 | "%3d: %s", | |
77 | out.prompt('project> ') | 77 | i + 1, |
78 | out.flush() | 78 | project.RelPath(local=opt.this_manifest_only) + "/", |
79 | try: | 79 | ) |
80 | a = sys.stdin.readline() | 80 | out.nl() |
81 | except KeyboardInterrupt: | 81 | out.nl() |
82 | out.nl() | 82 | |
83 | break | 83 | out.write("%3d: (", 0) |
84 | if a == '': | 84 | out.prompt("q") |
85 | out.nl() | 85 | out.write("uit)") |
86 | break | 86 | out.nl() |
87 | 87 | ||
88 | a = a.strip() | 88 | out.prompt("project> ") |
89 | if a.lower() in ('q', 'quit', 'exit'): | 89 | out.flush() |
90 | break | 90 | try: |
91 | if not a: | 91 | a = sys.stdin.readline() |
92 | continue | 92 | except KeyboardInterrupt: |
93 | 93 | out.nl() | |
94 | try: | 94 | break |
95 | a_index = int(a) | 95 | if a == "": |
96 | except ValueError: | 96 | out.nl() |
97 | a_index = None | 97 | break |
98 | 98 | ||
99 | if a_index is not None: | 99 | a = a.strip() |
100 | if a_index == 0: | 100 | if a.lower() in ("q", "quit", "exit"): |
101 | break | 101 | break |
102 | if 0 < a_index and a_index <= len(all_projects): | 102 | if not a: |
103 | _AddI(all_projects[a_index - 1]) | 103 | continue |
104 | continue | 104 | |
105 | 105 | try: | |
106 | projects = [ | 106 | a_index = int(a) |
107 | p for p in all_projects | 107 | except ValueError: |
108 | if a in [p.name, p.RelPath(local=opt.this_manifest_only)]] | 108 | a_index = None |
109 | if len(projects) == 1: | 109 | |
110 | _AddI(projects[0]) | 110 | if a_index is not None: |
111 | continue | 111 | if a_index == 0: |
112 | print('Bye.') | 112 | break |
113 | if 0 < a_index and a_index <= len(all_projects): | ||
114 | _AddI(all_projects[a_index - 1]) | ||
115 | continue | ||
116 | |||
117 | projects = [ | ||
118 | p | ||
119 | for p in all_projects | ||
120 | if a in [p.name, p.RelPath(local=opt.this_manifest_only)] | ||
121 | ] | ||
122 | if len(projects) == 1: | ||
123 | _AddI(projects[0]) | ||
124 | continue | ||
125 | print("Bye.") | ||
113 | 126 | ||
114 | 127 | ||
115 | def _AddI(project): | 128 | def _AddI(project): |
116 | p = GitCommand(project, ['add', '--interactive'], bare=False) | 129 | p = GitCommand(project, ["add", "--interactive"], bare=False) |
117 | p.Wait() | 130 | p.Wait() |