git_squash_branch.py 992 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/usr/bin/env python3
  2. # Copyright 2014 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. import argparse
  6. import sys
  7. import gclient_utils
  8. import git_common
  9. def main(args):
  10. if gclient_utils.IsEnvCog():
  11. print('squash-branch command is not supported in non-git environment.',
  12. file=sys.stderr)
  13. return 1
  14. parser = argparse.ArgumentParser()
  15. parser.add_argument(
  16. '-m',
  17. '--message',
  18. metavar='<msg>',
  19. default=None,
  20. help='Use the given <msg> as the first line of the commit message.')
  21. opts = parser.parse_args(args)
  22. if git_common.is_dirty_git_tree('squash-branch'):
  23. return 1
  24. git_common.squash_current_branch(opts.message)
  25. return 0
  26. if __name__ == '__main__':
  27. try:
  28. sys.exit(main(sys.argv[1:]))
  29. except KeyboardInterrupt:
  30. sys.stderr.write('interrupted\n')
  31. sys.exit(1)