Exemplo 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()
Exemplo n.º 2
0
 def test_parse_hours_flag(self):
     args = ['commit', '-m', 'fooed a bar', '--hours', '3']
     self.assertEqual(commit.parse_hours_flag(args), 3.0)
     self.assertEqual(args, ['commit', '-m', 'fooed a bar'])
     self.assertEqual(commit.parse_hours_flag(args), False)
     self.assertEqual(args, ['commit', '-m', 'fooed a bar'])