OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2014 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2014 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """This module contains functions for using git.""" | 6 """This module contains functions for using git.""" |
7 | 7 |
8 import os | 8 import os |
9 import re | 9 import re |
10 import shell_utils | 10 import shell_utils |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 if remote: | 82 if remote: |
83 cmd.append(remote) | 83 cmd.append(remote) |
84 shell_utils.run(cmd) | 84 shell_utils.run(cmd) |
85 | 85 |
86 | 86 |
87 def GetRemoteMasterHash(git_url): | 87 def GetRemoteMasterHash(git_url): |
88 return shell_utils.run([GIT, 'ls-remote', git_url, '--verify', | 88 return shell_utils.run([GIT, 'ls-remote', git_url, '--verify', |
89 'refs/heads/master']).rstrip() | 89 'refs/heads/master']).rstrip() |
90 | 90 |
91 | 91 |
| 92 def GetModifiedFiles(): |
| 93 """Returns a list of locally modified files within the current working dir. |
| 94 """ |
| 95 return shell_utils.run([GIT, 'ls-files', '-m']).splitlines() |
| 96 |
| 97 |
92 def GetCurrentBranch(): | 98 def GetCurrentBranch(): |
93 return shell_utils.run([GIT, 'rev-parse', '--abbrev-ref', 'HEAD']).rstrip() | 99 return shell_utils.run([GIT, 'rev-parse', '--abbrev-ref', 'HEAD']).rstrip() |
94 | 100 |
95 | 101 |
96 class GitBranch(object): | 102 class GitBranch(object): |
97 """Class to manage git branches. | 103 """Class to manage git branches. |
98 | 104 |
99 This class allows one to create a new branch in a repository to make changes, | 105 This class allows one to create a new branch in a repository to make changes, |
100 then it commits the changes, switches to master branch, and deletes the | 106 then it commits the changes, switches to master branch, and deletes the |
101 created temporary branch upon exit. | 107 created temporary branch upon exit. |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 shutil.rmtree(self._git_root) | 242 shutil.rmtree(self._git_root) |
237 | 243 |
238 def _run_in_git_root(self, args): | 244 def _run_in_git_root(self, args): |
239 """Run an external command with cwd set to self._git_root. | 245 """Run an external command with cwd set to self._git_root. |
240 | 246 |
241 Returns the command's output as a byte string. | 247 Returns the command's output as a byte string. |
242 | 248 |
243 Raises an Exception if the command fails. | 249 Raises an Exception if the command fails. |
244 """ | 250 """ |
245 return subprocess.check_output(args=args, cwd=self._git_root) | 251 return subprocess.check_output(args=args, cwd=self._git_root) |
OLD | NEW |