blob: 5346eb1fd21a6afc5cb72af8e35363e44d119292 [file] [log] [blame]
wfrichar@chromium.orga72bd942010-03-26 19:45:59 +00001#!/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
Raul Tambre80ee78e2019-05-06 22:41:05 +00008from __future__ import print_function
9
piman@chromium.orgf43d0192010-04-15 02:36:04 +000010import gclient_utils
wfrichar@chromium.orga72bd942010-03-26 19:45:59 +000011import os
12import re
13import subprocess
14import sys
15
16
17def show_dir(full_name, relative_name, color):
18 """Display active work in a single git repo."""
19
20 def show_name():
21 """Display the directory name."""
22
23 if color:
24 sys.stdout.write('========= %s[44m%s[37m%s%s[0m ========\n' %
25 (chr(27), chr(27), relative_name, chr(27)))
26 else:
27 sys.stdout.write('========= %s ========\n' % relative_name)
28
29 lines_printed = 0
30
31 cmd = ['git', 'branch', '-v']
32 if color:
33 cmd.append('--color')
34
35 branch = subprocess.Popen(cmd,
36 cwd=full_name,
37 stdout=subprocess.PIPE).communicate()[0].rstrip()
38
39 if len(branch.splitlines()) > 1:
40 if lines_printed == 0:
41 show_name()
42 lines_printed += 1
Raul Tambre80ee78e2019-05-06 22:41:05 +000043 print(branch)
wfrichar@chromium.orga72bd942010-03-26 19:45:59 +000044
45 status = subprocess.Popen(['git', 'status'],
46 cwd=full_name,
47 stdout=subprocess.PIPE).communicate()[0].rstrip()
48
49 if len(status.splitlines()) > 2:
50 if lines_printed == 0:
51 show_name()
52 if lines_printed == 1:
Raul Tambre80ee78e2019-05-06 22:41:05 +000053 print('---------------')
54 print(status)
wfrichar@chromium.orga72bd942010-03-26 19:45:59 +000055
56
wfrichar@chromium.orga72bd942010-03-26 19:45:59 +000057def main():
58 """Take no arguments."""
59
60 color = False
61
62 if os.isatty(1):
63 color = True
64
65 base = os.path.basename(os.getcwd())
piman@chromium.orgf43d0192010-04-15 02:36:04 +000066 root, entries = gclient_utils.GetGClientRootAndEntries()
wfrichar@chromium.orga72bd942010-03-26 19:45:59 +000067
piman@chromium.orgf43d0192010-04-15 02:36:04 +000068 # which entries map to a git repos?
sbc@chromium.orgc965a482012-09-12 21:02:02 +000069 raw = [k for k, v in entries.items() if v and not re.search('svn', v)]
wfrichar@chromium.orga72bd942010-03-26 19:45:59 +000070 raw.sort()
71
72 # We want to use the full path for testing, but we want to use the relative
73 # path for display.
wfrichar@chromium.orga72bd942010-03-26 19:45:59 +000074 fulldirs = map(lambda(p): os.path.normpath(os.path.join(root, p)), raw)
75 reldirs = map(lambda(p): re.sub('^' + base, '.', p), raw)
76
77 for full_path, relative_path in zip(fulldirs, reldirs):
78 show_dir(full_path, relative_path, color)
79
80if __name__ == '__main__':
81 main()