Esempio n. 1
0
def commit_main(args):
    # commits are NOT handled by argparse. `args` are passed to this function
    # as they are from sys.argv.
    u = User()
    invid = u.active_invoice_rowid
    if invid == 0:
        fprintf(
            "GITIME ERROR: You do not have an active invoice set. "
            "You won't be able to record your hours without one. "
            "Create an invoice with the command: `gitime invoice -n <invoice "
            "name>` first. Your commit has NOT been made.", file=sys.stderr)
        sys.exit()
    inv = Invoice(invid)
    raw_hours = parse_hours_flag(args)
    if raw_hours is not False:
        hours = round(raw_hours / inv.rounding) * inv.rounding
    else:
        hours = u.time_tracked(inv)
        if hours <= 0:
            fprintf(
                "GITIME ERROR: You didn't specify a number of hours, and the "
                "timer hasn't recorded anything. Run this command with the "
                "`--hours <hour count>` flag, or use the timer to track your "
                "time. Your commit has NOT been made."), file=sys.stderr)
            sys.exit()
        u.reset_timer()
    message = parse_commit_message(args)
    if not message:
        fprintf("GITIME ERROR: Could not find a message in your commit.", 
            file=sys.stderr)
        sys.exit()
Esempio n. 2
0
 def test_parse_commit_message(self):
     self.assertEqual(commit.parse_commit_message(['git', 'commit', '-am', 'did a thing']),
         'did a thing')
     self.assertEqual(commit.parse_commit_message(['git', 'commit', '-mq', 'didn\\\'t do a thing', '--short']),
         'didn\\\'t do a thing')
     self.assertEqual(commit.parse_commit_message(['git', 'commit', '-a', '--message', 'did a thing']),
         'did a thing')
     self.assertEqual(commit.parse_commit_message(['git', 'commit', '-a', "--message='didn\\\'t do a thing'"]),
         'didn\\\'t do a thing')
     args = ['git', 'commit', '-m', 'did "a t\\"hing']
     commit.parse_commit_message(args)
     self.assertEqual(args, ['git', 'commit', '-m', '"did \\"a t\\"hing"'])