OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 | 2 |
3 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 3 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
4 # for details. All rights reserved. Use of this source code is governed by a | 4 # for details. All rights reserved. Use of this source code is governed by a |
5 # BSD-style license that can be found in the LICENSE file. | 5 # BSD-style license that can be found in the LICENSE file. |
6 | 6 |
7 import optparse | 7 import optparse |
8 import os | 8 import os |
9 import platform | 9 import platform |
10 import subprocess | 10 import subprocess |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 results, _ = run_cmd(['svn', 'st']) | 72 results, _ = run_cmd(['svn', 'st']) |
73 else: | 73 else: |
74 results, _ = run_cmd(['git', 'status']) | 74 results, _ = run_cmd(['git', 'status']) |
75 for line in results.split('\n'): | 75 for line in results.split('\n'): |
76 if not is_git and (not line.strip().startswith('?') and line != ''): | 76 if not is_git and (not line.strip().startswith('?') and line != ''): |
77 return True | 77 return True |
78 elif is_git and ('Changes to be committed' in line or | 78 elif is_git and ('Changes to be committed' in line or |
79 'Changes not staged for commit:' in line): | 79 'Changes not staged for commit:' in line): |
80 return True | 80 return True |
81 if is_git: | 81 if is_git: |
82 p = subprocess.Popen(['git', 'log', '-1'], stdout=subprocess.PIPE, shell=Tru
e) | 82 p = subprocess.Popen(['git', 'log', '-1'], stdout=subprocess.PIPE, |
| 83 shell=(platform.system()=='Windows')) |
83 output, _ = p.communicate() | 84 output, _ = p.communicate() |
84 if find_git_info(output) == None: | 85 if find_git_info(output) == None: |
85 return True | 86 return True |
86 return False | 87 return False |
87 | 88 |
88 def run_cmd(cmd_list, suppress_output=False, std_in=''): | 89 def run_cmd(cmd_list, suppress_output=False, std_in=''): |
89 """Run the specified command and print out any output to stdout.""" | 90 """Run the specified command and print out any output to stdout.""" |
90 print ' '.join(cmd_list) | 91 print ' '.join(cmd_list) |
91 p = subprocess.Popen(cmd_list, stdout=subprocess.PIPE, stderr=subprocess.PIPE, | 92 p = subprocess.Popen(cmd_list, stdout=subprocess.PIPE, stderr=subprocess.PIPE, |
92 stdin=subprocess.PIPE, | 93 stdin=subprocess.PIPE, |
93 shell=(platform.system()=='Windows')) | 94 shell=(platform.system()=='Windows')) |
94 output, stderr = p.communicate(std_in) | 95 output, stderr = p.communicate(std_in) |
95 if output and not suppress_output: | 96 if output and not suppress_output: |
96 print output | 97 print output |
97 if stderr and not suppress_output: | 98 if stderr and not suppress_output: |
98 print stderr | 99 print stderr |
99 return (output, stderr) | 100 return (output, stderr) |
100 | 101 |
101 def runs_git(): | 102 def runs_git(): |
102 """Returns True if we're standing in an svn-git repository.""" | 103 """Returns True if we're standing in an svn-git repository.""" |
103 p = subprocess.Popen(['svn', 'info'], stdout=subprocess.PIPE, | 104 p = subprocess.Popen(['svn', 'info'], stdout=subprocess.PIPE, |
104 stderr=subprocess.PIPE, shell=True) | 105 stderr=subprocess.PIPE, |
| 106 shell=(platform.system()=='Windows')) |
105 output, err = p.communicate() | 107 output, err = p.communicate() |
106 if err != None and 'is not a working copy' in err: | 108 if err != None and 'is not a working copy' in err: |
107 p = subprocess.Popen(['git', 'status'], stdout=subprocess.PIPE, shell=True) | 109 p = subprocess.Popen(['git', 'status'], stdout=subprocess.PIPE, |
| 110 shell=(platform.system()=='Windows')) |
108 output, _ = p.communicate() | 111 output, _ = p.communicate() |
109 if 'fatal: Not a git repository' in output: | 112 if 'fatal: Not a git repository' in output: |
110 maybe_fail('Error: not running git or svn.') | 113 maybe_fail('Error: not running git or svn.') |
111 else: | 114 else: |
112 return True | 115 return True |
113 return False | 116 return False |
114 | 117 |
115 def find_git_info(git_log, rev_num=None): | 118 def find_git_info(git_log, rev_num=None): |
116 """Determine the latest svn revision number if rev_num = None, or find the | 119 """Determine the latest svn revision number if rev_num = None, or find the |
117 git commit_id that corresponds to a particular svn revision number. | 120 git commit_id that corresponds to a particular svn revision number. |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 user_input=True) | 187 user_input=True) |
185 if git_user: | 188 if git_user: |
186 run_cmd(['git', 'cl', 'rebase']) | 189 run_cmd(['git', 'cl', 'rebase']) |
187 run_cmd(['gclient', 'sync']) | 190 run_cmd(['gclient', 'sync']) |
188 revert(revisions[0], revisions[1], git_user) | 191 revert(revisions[0], revisions[1], git_user) |
189 print ('Now, create a CL and submit! The buildbots and your teammates thank ' | 192 print ('Now, create a CL and submit! The buildbots and your teammates thank ' |
190 'you!') | 193 'you!') |
191 | 194 |
192 if __name__ == '__main__': | 195 if __name__ == '__main__': |
193 main() | 196 main() |
OLD | NEW |