blob: 23b4f483db419fa6e33b2264530a812e68ec5f87 [file] [log] [blame]
[email protected]a72bd942010-03-26 19:45:591#!/usr/bin/env python
2# Copyright (c) 2010 The Chromium Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6"""Display active git branches and code changes in a chromiumos workspace."""
7
[email protected]f43d0192010-04-15 02:36:048import gclient_utils
[email protected]a72bd942010-03-26 19:45:599import os
10import re
11import subprocess
12import sys
13
14
15def show_dir(full_name, relative_name, color):
16 """Display active work in a single git repo."""
17
18 def show_name():
19 """Display the directory name."""
20
21 if color:
22 sys.stdout.write('========= %s[44m%s[37m%s%s[0m ========\n' %
23 (chr(27), chr(27), relative_name, chr(27)))
24 else:
25 sys.stdout.write('========= %s ========\n' % relative_name)
26
27 lines_printed = 0
28
29 cmd = ['git', 'branch', '-v']
30 if color:
31 cmd.append('--color')
32
33 branch = subprocess.Popen(cmd,
34 cwd=full_name,
35 stdout=subprocess.PIPE).communicate()[0].rstrip()
36
37 if len(branch.splitlines()) > 1:
38 if lines_printed == 0:
39 show_name()
40 lines_printed += 1
41 print branch
42
43 status = subprocess.Popen(['git', 'status'],
44 cwd=full_name,
45 stdout=subprocess.PIPE).communicate()[0].rstrip()
46
47 if len(status.splitlines()) > 2:
48 if lines_printed == 0:
49 show_name()
50 if lines_printed == 1:
51 print '---------------'
52 print status
53
54
[email protected]a72bd942010-03-26 19:45:5955def main():
56 """Take no arguments."""
57
58 color = False
59
60 if os.isatty(1):
61 color = True
62
63 base = os.path.basename(os.getcwd())
[email protected]f43d0192010-04-15 02:36:0464 root, entries = gclient_utils.GetGClientRootAndEntries()
[email protected]a72bd942010-03-26 19:45:5965
[email protected]f43d0192010-04-15 02:36:0466 # which entries map to a git repos?
[email protected]c965a482012-09-12 21:02:0267 raw = [k for k, v in entries.items() if v and not re.search('svn', v)]
[email protected]a72bd942010-03-26 19:45:5968 raw.sort()
69
70 # We want to use the full path for testing, but we want to use the relative
71 # path for display.
[email protected]a72bd942010-03-26 19:45:5972 fulldirs = map(lambda(p): os.path.normpath(os.path.join(root, p)), raw)
73 reldirs = map(lambda(p): re.sub('^' + base, '.', p), raw)
74
75 for full_path, relative_path in zip(fulldirs, reldirs):
76 show_dir(full_path, relative_path, color)
77
78if __name__ == '__main__':
79 main()