示例#1
0
    def rm(self, sha):
        match = self.match_or_error(sha)
        print("Remove permanently '%s'" % match)
        print("(Press CTRL-C to abort...)")
        try:
            raw_input()
        except KeyboardInterrupt:
            log.printerr("Abort!")
            sys.exit(1)

        _, basename = os.path.split(match)
        sha7 = misc.chop(basename, 7)

        # prepare the critical section
        curr_branch = self.repo.active_branch.name
        curr_dir = os.getcwd()
        msg = "Removed ticket '%s'" % sha7
        abs_ticket_dir = os.path.join(self.repo.working_dir, it.TICKET_DIR)

        # Commit the new itdb to the repo
        try:
            os.chdir(self.repo.working_dir)
            self.repo.git.symbolic_ref(
                ['HEAD', 'refs/heads/' + it.ITDB_BRANCH])
            self.repo.git.commit(['-m', msg, match])
            print("ticket '%s' removed" % sha7)
        except Exception:
            log.printerr("Error commiting change!")
            sys.exit(1)
        finally:
            self.repo.git.symbolic_ref(['HEAD', 'refs/heads/' + curr_branch])
            self.repo.git.reset(['HEAD', '--', abs_ticket_dir])
            misc.rmdirs(abs_ticket_dir)
            os.chdir(curr_dir)
示例#2
0
文件: gitit.py 项目: dongrote/git-it
    def init(self):
        if self.itdb_exists():
            print 'Already initialized issue database in branch \'%s\'.' % \
                                                                                                                         it.ITDB_BRANCH
            return

        # else, initialize the new .it database alongside the .git repo
        gitrepo = repo.find_git_repo()
        if not gitrepo:
            log.printerr('Not a valid Git repository.')
        else:
            parent, _ = os.path.split(gitrepo)
            ticket_dir = os.path.join(parent, it.TICKET_DIR)
            hold_file = os.path.join(ticket_dir, it.HOLD_FILE)
            misc.mkdirs(ticket_dir)
            misc.write_file_contents(hold_file, \
                         'This is merely a placeholder file for git-it that prevents ' + \
                         'this directory from\nbeing pruned by Git.')

            # Commit the new itdb to the repo
            curr_branch = git.current_branch()
            git.change_head_branch('git-it')
            git.command_lines('add', [hold_file])
            msg = 'Initialized empty ticket database.'
            git.command_lines('commit', ['-m', msg, hold_file])
            os.remove(hold_file)
            os.rmdir(ticket_dir)
            git.change_head_branch(curr_branch)
            abs_ticket_dir = os.path.join(repo.find_root(), it.TICKET_DIR)
            git.command_lines('reset', ['HEAD', abs_ticket_dir])
            misc.rmdirs(abs_ticket_dir)
            print 'Initialized empty ticket database.'
示例#3
0
文件: gitit.py 项目: maurin/git-it
  def edit(self, sha):
    i, rel, fullsha, match = self.get_ticket(sha)
    sha7 = misc.chop(fullsha, 7)

    # Save the contents of this ticket to a file, so it can be edited
    i.save(it.EDIT_TMP_FILE)
    timestamp1 = os.path.getmtime(it.EDIT_TMP_FILE)
    success = os.system('vim "%s"' % it.EDIT_TMP_FILE) == 0
    timestamp2 = os.path.getmtime(it.EDIT_TMP_FILE)
    if success:
      if timestamp1 < timestamp2:
        i = ticket.create_from_file(it.EDIT_TMP_FILE, fullsha, rel)

        # Now, when the edit has succesfully taken place, switch branches, commit,
        # and switch back
        curr_branch = git.current_branch()
        git.change_head_branch('git-it')
        msg = 'ticket \'%s\' edited' % sha7
        i.save()
        git.command_lines('commit', ['-m', msg, i.filename()])
        git.change_head_branch(curr_branch)
        abs_ticket_dir = os.path.join(repo.find_root(), it.TICKET_DIR)
        git.command_lines('reset', ['HEAD', abs_ticket_dir])
        misc.rmdirs(abs_ticket_dir)
        print 'ticket \'%s\' edited succesfully' % sha7
        print ''
        self.list()
      else:
        print 'editing of ticket \'%s\' cancelled' % sha7
    else:
      log.printerr('editing of ticket \'%s\' failed' % sha7)

    # Remove the temporary file
    os.remove(it.EDIT_TMP_FILE)
示例#4
0
    def reopen_ticket(self, sha):
        i, _, fullsha, match = self.get_ticket(sha)
        sha7 = misc.chop(fullsha, 7)
        if i.status == 'open':
            log.printerr("Ticket '%s' already open" % sha7)
            sys.exit(1)

        # Now, when the edit has succesfully taken place, switch branches, commit,
        # and switch back
        curr_branch = self.repo.active_branch.name
        curr_dir = os.getcwd()
        msg = "Ticket '%s' reopened" % sha7
        abs_ticket_dir = os.path.join(self.repo.working_dir, it.TICKET_DIR)

        try:
            os.chdir(self.repo.working_dir)
            self.repo.git.symbolic_ref(
                ['HEAD', 'refs/heads/' + it.ITDB_BRANCH])
            i.status = 'open'
            i.save()
            self.repo.git.commit(['-m', msg, match])
            print(msg)

        finally:
            self.repo.git.symbolic_ref(['HEAD', 'refs/heads/' + curr_branch])
            self.repo.git.reset(['HEAD', '--', abs_ticket_dir])
            misc.rmdirs(abs_ticket_dir)
            os.chdir(curr_dir)
示例#5
0
    def edit(self, sha):
        i, rel, fullsha, match = self.get_ticket(sha)
        sha7 = misc.chop(fullsha, 7)

        # Save the contents of this ticket to a file, so it can be edited
        i.save(it.EDIT_TMP_FILE)
        timestamp1 = os.path.getmtime(it.EDIT_TMP_FILE)
        success = os.system('vim "%s"' % it.EDIT_TMP_FILE) == 0
        timestamp2 = os.path.getmtime(it.EDIT_TMP_FILE)
        if success:
            if timestamp1 < timestamp2:
                i = ticket.create_from_file(it.EDIT_TMP_FILE, fullsha, rel)

                # Now, when the edit has succesfully taken place, switch branches, commit,
                # and switch back
                curr_branch = git.current_branch()
                git.change_head_branch('git-it')
                msg = 'ticket \'%s\' edited' % sha7
                i.save()
                git.command_lines('commit', ['-m', msg, i.filename()])
                git.change_head_branch(curr_branch)
                abs_ticket_dir = os.path.join(repo.find_root(), it.TICKET_DIR)
                git.command_lines('reset', ['HEAD', abs_ticket_dir])
                misc.rmdirs(abs_ticket_dir)
                print 'ticket \'%s\' edited succesfully' % sha7
                print ''
                self.list()
            else:
                print 'editing of ticket \'%s\' cancelled' % sha7
        else:
            log.printerr('editing of ticket \'%s\' failed' % sha7)

        # Remove the temporary file
        os.remove(it.EDIT_TMP_FILE)
示例#6
0
    def init(self):
        if self.itdb_exists():
            print 'Already initialized issue database in branch \'%s\'.' % \
                                                                   it.ITDB_BRANCH
            return

        # else, initialize the new .it database alongside the .git repo
        gitrepo = repo.find_git_repo()
        if not gitrepo:
            log.printerr('Not a valid Git repository.')
        else:
            parent, _ = os.path.split(gitrepo)
            ticket_dir = os.path.join(parent, it.TICKET_DIR)
            hold_file = os.path.join(ticket_dir, it.HOLD_FILE)
            misc.mkdirs(ticket_dir)
            misc.write_file_contents(hold_file, \
                   'This is merely a placeholder file for git-it that prevents ' + \
                   'this directory from\nbeing pruned by Git.')

            # Commit the new itdb to the repo
            curr_branch = git.current_branch()
            git.change_head_branch('git-it')
            git.command_lines('add', [hold_file])
            msg = 'Initialized empty ticket database.'
            git.command_lines('commit', ['-m', msg, hold_file])
            os.remove(hold_file)
            os.rmdir(ticket_dir)
            git.change_head_branch(curr_branch)
            abs_ticket_dir = os.path.join(repo.find_root(), it.TICKET_DIR)
            git.command_lines('reset', ['HEAD', abs_ticket_dir])
            misc.rmdirs(abs_ticket_dir)
            print 'Initialized empty ticket database.'
示例#7
0
    def finish_ticket(self, sha, new_status):
        i, _, fullsha, match = self.get_ticket(sha)
        sha7 = misc.chop(fullsha, 7)
        if i.status not in ['open', 'test']:
            log.printerr("Ticket '%s' already %s" % (sha7, i.status))
            sys.exit(1)

        # Now, when the edit has succesfully taken place, switch branches, commit,
        # and switch back
        curr_branch = self.repo.active_branch.name
        curr_dir = os.getcwd()
        msg = "%s ticket '%s'" % (i.status, sha7)
        msg = msg.capitalize()
        abs_ticket_dir = os.path.join(self.repo.working_dir, it.TICKET_DIR)

        try:
            os.chdir(self.repo.working_dir)
            self.repo.git.symbolic_ref(
                ['HEAD', 'refs/heads/' + it.ITDB_BRANCH])
            i.status = new_status
            i.save()
            self.repo.git.commit(['-m', msg, match])
            print("Ticket '%s' now %s" % (sha7, new_status))
        except Exception:
            log.printerr("Error commiting changes to ticket '%s'" % sha7)
        finally:
            self.repo.git.symbolic_ref(['HEAD', 'refs/heads/' + curr_branch])
            self.repo.git.reset(['HEAD', '--', abs_ticket_dir])
            misc.rmdirs(abs_ticket_dir)
            os.chdir(curr_dir)
示例#8
0
    def leave_ticket(self, sha):
        i, _, fullsha, match = self.get_ticket(sha)
        sha7 = misc.chop(fullsha, 7)
        fullname = self.get_cfg('name', section='user', default='Anonymous')

        if i.assigned_to == '-':
            print("Ticket '%s' already left alone" % (sha7))
            return

        # prepare for the critical section
        curr_branch = self.repo.active_branch.name
        curr_dir = os.getcwd()
        msg = "Ticket %s was left alone from '%s'" % (sha7, fullname)
        abs_ticket_dir = os.path.join(self.repo.working_dir, it.TICKET_DIR)

        try:
            os.chdir(self.repo.working_dir)
            self.repo.git.symbolic_ref(
                ['HEAD', 'refs/heads/' + it.ITDB_BRANCH])
            i.assigned_to = '-'
            i.save()
            self.repo.git.commit(['-m', msg, match])
            print(msg)
        except Exception:
            print("Error commiting change -- cleanup")
        finally:
            self.repo.git.symbolic_ref(['HEAD', 'refs/heads/' + curr_branch])
            self.repo.git.reset(['HEAD', '--', abs_ticket_dir])
            misc.rmdirs(abs_ticket_dir)
            os.chdir(curr_dir)
示例#9
0
    def init(self):
        """ Initializes a ITDB if it does not exists. Otherwise search for
            a remote ITDB an branch from it.
        """
        # check wheter it is already initialzed
        if it.ITDB_BRANCH in [b.name for b in self.repo.branches]:
            # check for the hold file
            abs_hold_file = os.path.join(it.TICKET_DIR, it.HOLD_FILE)
            if abs_hold_file in [
                    x.path for x in self.itdb_tree.list_traverse(depth=1)
            ]:
                print("Issue database already initialized.")
                return

        # search for a ITDB on a remote branch
        for r in self.repo.remotes:
            for ref in r.refs:
                if ref.name.endswith(it.ITDB_BRANCH):
                    print("Initialize ticket database from %s." % ref.name)
                    self.repo.create_head('refs/heads/%s' % it.ITDB_BRANCH,
                                          ref.name)
                    return

        # else, initialize the new .it database alongside the .git repo
        gitrepo = self.repo.git_dir
        if not gitrepo:
            log.printerr("%s: Not a valid Git repository." % gitrepo)
            return

        #FIXME: use working_dir directly instead of assuming 'git_repo'
        #       is work_dir/.git
        parent, _ = os.path.split(gitrepo)
        ticket_dir = os.path.join(parent, it.TICKET_DIR)
        hold_file = os.path.join(ticket_dir, it.HOLD_FILE)
        curr_branch = self.repo.active_branch.name
        msg = "Initialized empty ticket database."
        abs_ticket_dir = os.path.join(self.repo.working_dir, it.TICKET_DIR)
        try:
            misc.mkdirs(ticket_dir)
            misc.write_file_contents(hold_file, \
                         'This is merely a placeholder file for git-it that prevents ' + \
                         'this directory from\nbeing pruned by Git.')

            # Commit the new itdb to the repo
            self.repo.git.symbolic_ref(
                ['HEAD', 'refs/heads/' + it.ITDB_BRANCH])
            self.repo.git.add([hold_file])
            self.repo.git.commit(['-m', msg, hold_file])
            print("Initialized empty ticket database.")
        except Exception:
            log.printerr("Error initialising ticket database.")

        finally:
            os.remove(hold_file)
            os.rmdir(ticket_dir)
            self.repo.git.symbolic_ref(['HEAD', 'refs/heads/' + curr_branch])
            self.repo.git.reset(['HEAD', '--', abs_ticket_dir])
            misc.rmdirs(abs_ticket_dir)
示例#10
0
    def edit(self, sha):
        i, rel, fullsha, match = self.get_ticket(sha)
        sha7 = misc.chop(fullsha, 7)

        # Save the contents of this ticket to a file, so it can be edited
        fd, filename = mkstemp(prefix='git-it.')
        i.save(filename)
        timestamp1 = os.path.getmtime(filename)
        success = os.system(
            self.get_cfg('editor', default='vim') + ' "%s"' % filename) == 0
        timestamp2 = os.path.getmtime(filename)
        if not success:
            log.printerr("Editing of ticket '%s' failed" % sha7)
            os.remove(filename)
            sys.exit(1)

        if timestamp1 >= timestamp2:
            print("Editing of ticket '%s' cancelled" % sha7)
            os.remove(filename)
            return

        try:
            i = ticket.create_from_file(filename, fullsha, rel)
        except ticket.MalformedTicketFieldException as e:
            log.printerr("Error parsing ticket: %s" % e)
            sys.exit(1)
        except ticket.MissingTicketFieldException as e:
            log.printerr("Error parsing ticket: %s" % e)
            sys.exit(1)

        # Now, when the edit has succesfully taken place, switch branches, commit,
        # and switch back
        curr_branch = self.repo.active_branch.name
        msg = "Ticket '%s' edited" % sha7
        abs_ticket_dir = os.path.join(self.repo.working_dir, it.TICKET_DIR)
        try:
            self.repo.git.symbolic_ref(
                ['HEAD', 'refs/heads/' + it.ITDB_BRANCH])
            i.save()
            self.repo.git.commit(['-m', msg, i.filename()])
            print("Ticket '%s' edited succesfully" % sha7)
        except Exception:
            log.printerr("Error commiting modified ticket.")

        finally:
            self.repo.git.symbolic_ref(['HEAD', 'refs/heads/' + curr_branch])
            self.repo.git.reset(['HEAD', '--', abs_ticket_dir])
            misc.rmdirs(abs_ticket_dir)

        # Remove the temporary file
        os.remove(filename)
示例#11
0
    def leave_ticket(self, sha):
        i, _, fullsha, match = self.get_ticket(sha)
        sha7 = misc.chop(sha, 7)

        curr_branch = git.current_branch()
        git.change_head_branch('git-it')
        msg = 'ticket \'%s\' left alone' % sha7
        i.assigned_to = '-'
        i.save()
        git.command_lines('commit', ['-m', msg, match], from_root=True)
        git.change_head_branch(curr_branch)
        abs_ticket_dir = os.path.join(repo.find_root(), it.TICKET_DIR)
        git.command_lines('reset', ['HEAD', abs_ticket_dir])
        misc.rmdirs(abs_ticket_dir)
        print 'ticket \'%s\' left alone' % sha7
示例#12
0
    def rm(self, sha):
        match = self.match_or_error(sha)
        _, basename = os.path.split(match)
        sha7 = misc.chop(basename, 7)

        # Commit the new itdb to the repo
        curr_branch = git.current_branch()
        git.change_head_branch('git-it')
        msg = 'removed ticket \'%s\'' % sha7
        git.command_lines('commit', ['-m', msg, match])
        git.change_head_branch(curr_branch)
        abs_ticket_dir = os.path.join(repo.find_root(), it.TICKET_DIR)
        git.command_lines('reset', ['HEAD', abs_ticket_dir])
        misc.rmdirs(abs_ticket_dir)
        print 'ticket \'%s\' removed' % sha7
示例#13
0
文件: gitit.py 项目: dongrote/git-it
    def leave_ticket(self, sha):
        i, _, fullsha, match = self.get_ticket(sha)
        sha7 = misc.chop(sha, 7)

        curr_branch = git.current_branch()
        git.change_head_branch('git-it')
        msg = 'ticket \'%s\' left alone' % sha7
        i.assigned_to = '-'
        i.save()
        git.command_lines('commit', ['-m', msg, match], from_root=True)
        git.change_head_branch(curr_branch)
        abs_ticket_dir = os.path.join(repo.find_root(), it.TICKET_DIR)
        git.command_lines('reset', ['HEAD', abs_ticket_dir])
        misc.rmdirs(abs_ticket_dir)
        print 'ticket \'%s\' left alone' % sha7
示例#14
0
文件: gitit.py 项目: dongrote/git-it
    def rm(self, sha):
        match = self.match_or_error(sha)
        _, basename = os.path.split(match)
        sha7 = misc.chop(basename, 7)

        # Commit the new itdb to the repo
        curr_branch = git.current_branch()
        git.change_head_branch('git-it')
        msg = 'removed ticket \'%s\'' % sha7
        git.command_lines('commit', ['-m', msg, match], from_root=True)
        git.change_head_branch(curr_branch)
        abs_ticket_dir = os.path.join(repo.find_root(), it.TICKET_DIR)
        git.command_lines('reset', ['HEAD', abs_ticket_dir])
        misc.rmdirs(abs_ticket_dir)
        print 'ticket \'%s\' removed'% sha7
示例#15
0
    def take_ticket(self, sha):
        i, _, fullsha, match = self.get_ticket(sha)
        sha7 = misc.chop(sha, 7)

        curr_branch = git.current_branch()
        git.change_head_branch('git-it')
        fullname = os.popen('git config user.name').read().strip()
        msg = 'ticket \'%s\' taken by %s' % (sha7, fullname)
        i.assigned_to = fullname
        i.save()
        git.command_lines('commit', ['-m', msg, match])
        git.change_head_branch(curr_branch)
        abs_ticket_dir = os.path.join(repo.find_root(), it.TICKET_DIR)
        git.command_lines('reset', ['HEAD', abs_ticket_dir])
        misc.rmdirs(abs_ticket_dir)
        print 'ticket \'%s\' taken' % sha7
        print ''
        self.list()
示例#16
0
文件: gitit.py 项目: maurin/git-it
  def take_ticket(self, sha):
    i, _, fullsha, match = self.get_ticket(sha)
    sha7 = misc.chop(sha, 7)

    curr_branch = git.current_branch()
    git.change_head_branch('git-it')
    fullname = os.popen('git config user.name').read().strip()
    msg = 'ticket \'%s\' taken by %s' % (sha7, fullname)
    i.assigned_to = fullname
    i.save()
    git.command_lines('commit', ['-m', msg, match])
    git.change_head_branch(curr_branch)
    abs_ticket_dir = os.path.join(repo.find_root(), it.TICKET_DIR)
    git.command_lines('reset', ['HEAD', abs_ticket_dir])
    misc.rmdirs(abs_ticket_dir)
    print 'ticket \'%s\' taken' % sha7
    print ''
    self.list()
示例#17
0
    def mv(self, sha, to_rel):
        self.require_itdb()
        i, rel, fullsha, src_path = self.get_ticket(sha)
        sha7 = misc.chop(fullsha, 7)

        src_dir = os.path.join(self.repo.working_dir, it.TICKET_DIR, rel)
        target_dir = os.path.join(self.repo.working_dir, it.TICKET_DIR, to_rel)
        target_path = os.path.join(target_dir, fullsha)
        if src_dir == target_dir:
            log.printerr("Ticket '%s' already in '%s'" % (sha7, to_rel))
            return

        # Create the target dir, if neccessary
        if not os.path.isdir(target_dir):
            misc.mkdirs(target_dir)

        # Try to move the file into it
        curr_branch = self.repo.active_branch.name
        msg = "Moved ticket '%s' (%s --> %s)" % (sha7, rel, to_rel)
        abs_ticket_dir = os.path.join(self.repo.working_dir, it.TICKET_DIR)
        try:
            # Commit the new itdb to the repo
            self.repo.git.symbolic_ref(
                ['HEAD', 'refs/heads/' + it.ITDB_BRANCH])

            i.save(target_path)
            if os.path.isfile(src_path):
                os.remove(src_path)

            self.repo.git.add([target_path])
            self.repo.git.commit(['-m', msg, src_path, target_path])
            print("Ticket '%s' moved to release '%s'" % (sha7, to_rel))
        except OSError as e:
            log.printerr("Could not move ticket '%s' to '%s':" %
                         (sha7, to_rel))
            log.printerr(e)
        except Exception:
            log.printerr("Could not move ticket '%s' to '%s':" %
                         (sha7, to_rel))

        finally:
            self.repo.git.symbolic_ref(['HEAD', 'refs/heads/' + curr_branch])
            self.repo.git.reset(['HEAD', '--', abs_ticket_dir])
            misc.rmdirs(abs_ticket_dir)
示例#18
0
    def new(self):
        self.require_itdb()

        # Create a fresh ticket
        try:
            i = ticket.create_interactive(self._gitcfg)
        except KeyboardInterrupt:
            print('')
            print("Aborting new ticket.")
            return None

        # Generate a SHA1 id
        s = sha1_constructor()
        s.update(i.__str__())
        s.update(os.getlogin())
        s.update(datetime.datetime.now().__str__())
        i.id = ticketname = s.hexdigest()

        # Save the ticket to disk
        i.save()
        sha7 = misc.chop(ticketname, 7)
        print("New ticket '%s' saved" % sha7)

        # Commit the new ticket to the 'aaa' branch
        curr_branch = self.repo.active_branch.name
        msg = "%s added ticket '%s'" % (i.issuer, sha7)
        msg = msg.capitalize()
        abs_ticket_dir = os.path.join(self.repo.working_dir, it.TICKET_DIR)

        try:
            self.repo.git.symbolic_ref(
                ['HEAD', 'refs/heads/' + it.ITDB_BRANCH])
            self.repo.git.add([i.filename()])
            self.repo.git.commit(['-m', msg, i.filename()])
        except:
            log.printerr("Error commiting changes to ticket '%s'" % sha7)
        finally:
            os.remove(i.filename())
            self.repo.git.rm(['--cached', i.filename()])
            self.repo.git.symbolic_ref(['HEAD', 'refs/heads/' + curr_branch])
            self.repo.git.reset(['HEAD', '--', abs_ticket_dir])
            misc.rmdirs(abs_ticket_dir)
        return i
示例#19
0
文件: gitit.py 项目: dongrote/git-it
    def finish_ticket(self, sha, new_status):
        i, _, fullsha, match = self.get_ticket(sha)
        sha7 = misc.chop(fullsha, 7)
        if i.status not in ['open', 'test']:
            log.printerr('ticket \'%s\' already %s' % (sha7, i.status))
            sys.exit(1)

        # Now, when the edit has succesfully taken place, switch branches, commit,
        # and switch back
        curr_branch = git.current_branch()
        git.change_head_branch('git-it')
        i.status = new_status
        msg = '%s ticket \'%s\'' % (i.status, sha7)
        i.save()
        git.command_lines('commit', ['-m', msg, match], from_root=True)
        git.change_head_branch(curr_branch)
        abs_ticket_dir = os.path.join(repo.find_root(), it.TICKET_DIR)
        git.command_lines('reset', ['HEAD', abs_ticket_dir])
        misc.rmdirs(abs_ticket_dir)
        print 'ticket \'%s\' %s' % (sha7, new_status)
示例#20
0
    def reopen_ticket(self, sha):
        i, _, fullsha, match = self.get_ticket(sha)
        sha7 = misc.chop(sha, 7)
        if i.status == 'open':
            log.printerr('ticket \'%s\' already open' % sha7)
            sys.exit(1)

        # Now, when the edit has succesfully taken place, switch branches, commit,
        # and switch back
        curr_branch = git.current_branch()
        git.change_head_branch('git-it')
        msg = 'ticket \'%s\' reopened' % sha7
        i.status = 'open'
        i.save()
        git.command_lines('commit', ['-m', msg, match], from_root=True)
        git.change_head_branch(curr_branch)
        abs_ticket_dir = os.path.join(repo.find_root(), it.TICKET_DIR)
        git.command_lines('reset', ['HEAD', abs_ticket_dir])
        misc.rmdirs(abs_ticket_dir)
        print 'ticket \'%s\' reopened' % sha7
示例#21
0
    def finish_ticket(self, sha, new_status):
        i, _, fullsha, match = self.get_ticket(sha)
        sha7 = misc.chop(fullsha, 7)
        if i.status not in ['open', 'test']:
            log.printerr('ticket \'%s\' already %s' % (sha7, i.status))
            sys.exit(1)

        # Now, when the edit has succesfully taken place, switch branches, commit,
        # and switch back
        curr_branch = git.current_branch()
        git.change_head_branch('git-it')
        i.status = new_status
        msg = '%s ticket \'%s\'' % (i.status, sha7)
        i.save()
        git.command_lines('commit', ['-m', msg, match], from_root=True)
        git.change_head_branch(curr_branch)
        abs_ticket_dir = os.path.join(repo.find_root(), it.TICKET_DIR)
        git.command_lines('reset', ['HEAD', abs_ticket_dir])
        misc.rmdirs(abs_ticket_dir)
        print 'ticket \'%s\' %s' % (sha7, new_status)
示例#22
0
文件: gitit.py 项目: dongrote/git-it
    def reopen_ticket(self, sha):
        i, _, fullsha, match = self.get_ticket(sha)
        sha7 = misc.chop(sha, 7)
        if i.status == 'open':
            log.printerr('ticket \'%s\' already open' % sha7)
            sys.exit(1)

        # Now, when the edit has succesfully taken place, switch branches, commit,
        # and switch back
        curr_branch = git.current_branch()
        git.change_head_branch('git-it')
        msg = 'ticket \'%s\' reopened' % sha7
        i.status = 'open'
        i.save()
        git.command_lines('commit', ['-m', msg, match], from_root=True)
        git.change_head_branch(curr_branch)
        abs_ticket_dir = os.path.join(repo.find_root(), it.TICKET_DIR)
        git.command_lines('reset', ['HEAD', abs_ticket_dir])
        misc.rmdirs(abs_ticket_dir)
        print 'ticket \'%s\' reopened' % sha7
示例#23
0
    def mv(self, sha, to_rel):
        self.require_itdb()
        i, rel, fullsha, src_path = self.get_ticket(sha)
        sha7 = misc.chop(fullsha, 7)

        src_dir = os.path.join(repo.find_root(), it.TICKET_DIR, rel)
        target_dir = os.path.join(repo.find_root(), it.TICKET_DIR, to_rel)
        target_path = os.path.join(target_dir, fullsha)
        if src_dir == target_dir:
            log.printerr('ticket \'%s\' already in \'%s\'' % (sha7, to_rel))
            return

        # Create the target dir, if neccessary
        if not os.path.isdir(target_dir):
            misc.mkdirs(target_dir)

        # Try to move the file into it
        try:
            # Commit the new itdb to the repo
            curr_branch = git.current_branch()
            git.change_head_branch('git-it')

            i.save(target_path)
            if os.path.isfile(src_path):
                os.remove(src_path)

            msg = 'moved ticket \'%s\' (%s --> %s)' % (sha7, rel, to_rel)
            git.command_lines('add', [target_path])
            git.command_lines('commit', ['-m', msg, src_path, target_path])
            git.change_head_branch(curr_branch)
            abs_ticket_dir = os.path.join(repo.find_root(), it.TICKET_DIR)
            git.command_lines('reset', ['HEAD', abs_ticket_dir])
            misc.rmdirs(abs_ticket_dir)

            print 'ticket \'%s\' moved to release \'%s\'' % (sha7, to_rel)
            print ''
            self.list()
        except OSError, e:
            log.printerr('could not move ticket \'%s\' to \'%s\':' %
                         (sha7, to_rel))
            log.printerr(e)
示例#24
0
 def reject_ticket(self, sha, message):
     i, _, fullsha, match = self.get_ticket(sha)
     sha7 = misc.chop(sha, 7)
     if 'rejected' == i.status:
         log.printerr('ticket \'%s\' already rejected' % sha7)
         sys.exit(1)
     if message is None or message == '':
         message = ticket.ask_for_pattern('Reason for rejection: ',
                                          ticket.not_empty)
     curr_branch = git.current_branch()
     git.change_head_branch('git-it')
     i.status = 'rejected'
     i.body = 'REJECTED: %s\n\n%s' % (message, i.body)
     msg = '%s ticket \'%s\'' % (i.status, sha7)
     i.save()
     git.command_lines('commit', ['-m', msg, match], from_root=True)
     git.change_head_branch(curr_branch)
     abs_ticket_dir = os.path.join(repo.find_root(), it.TICKET_DIR)
     git.command_lines('reset', ['HEAD', abs_ticket_dir])
     misc.rmdirs(abs_ticket_dir)
     print 'ticket \'%s\' rejected' % sha7
示例#25
0
文件: gitit.py 项目: dongrote/git-it
 def reject_ticket(self, sha, message):
     i, _, fullsha, match = self.get_ticket(sha)
     sha7 = misc.chop(sha, 7)
     if 'rejected' == i.status:
         log.printerr('ticket \'%s\' already rejected' % sha7)
         sys.exit(1)
     if message is None or message == '':
         message = ticket.ask_for_pattern(
             'Reason for rejection: ', ticket.not_empty)
     curr_branch = git.current_branch()
     git.change_head_branch('git-it')
     i.status = 'rejected'
     i.body = 'REJECTED: %s\n\n%s' % (message, i.body)
     msg = '%s ticket \'%s\'' % (i.status, sha7)
     i.save()
     git.command_lines('commit', ['-m', msg, match], from_root=True)
     git.change_head_branch(curr_branch)
     abs_ticket_dir = os.path.join(repo.find_root(), it.TICKET_DIR)
     git.command_lines('reset', ['HEAD', abs_ticket_dir])
     misc.rmdirs(abs_ticket_dir)
     print 'ticket \'%s\' rejected' % sha7
示例#26
0
    def edit(self, sha):
        i, rel, fullsha, match = self.get_ticket(sha)
        sha7 = misc.chop(fullsha, 7)

        # Save the contents of this ticket to a file, so it can be edited
        i.save(it.EDIT_TMP_FILE)
        timestamp1 = os.path.getmtime(it.EDIT_TMP_FILE)
        # fetch the editor command from the following sources in this order:
        #    - git config --local core.editor
        #    - git config --global core.editor
        #    - git config --system core.editor
        #    - $GIT_EDITOR
        #    - $EDITOR
        #    - /usr/bin/nano
        success = os.system('%s "%s"' %
                            (git.get_editor(), it.EDIT_TMP_FILE)) == 0
        timestamp2 = os.path.getmtime(it.EDIT_TMP_FILE)
        if success:
            if timestamp1 < timestamp2:
                try:
                    i = ticket.create_from_file(it.EDIT_TMP_FILE, fullsha, rel)
                except ticket.MalformedTicketFieldException, e:
                    print 'Error parsing ticket: %s' % e
                    sys.exit(1)
                except ticket.MissingTicketFieldException, e:
                    print 'Error parsing ticket: %s' % e
                    sys.exit(1)

                # Now, when the edit has succesfully taken place, switch branches, commit,
                # and switch back
                curr_branch = git.current_branch()
                git.change_head_branch('git-it')
                msg = 'ticket \'%s\' edited' % sha7
                i.save()
                git.command_lines('commit', ['-m', msg, i.filename()])
                git.change_head_branch(curr_branch)
                abs_ticket_dir = os.path.join(repo.find_root(), it.TICKET_DIR)
                git.command_lines('reset', ['HEAD', abs_ticket_dir])
                misc.rmdirs(abs_ticket_dir)
                print 'ticket \'%s\' edited succesfully' % sha7
示例#27
0
文件: gitit.py 项目: maurin/git-it
  def mv(self, sha, to_rel):
    self.require_itdb()
    i, rel, fullsha, src_path = self.get_ticket(sha)
    sha7 = misc.chop(fullsha, 7)

    src_dir = os.path.join(repo.find_root(), it.TICKET_DIR, rel)
    target_dir = os.path.join(repo.find_root(), it.TICKET_DIR, to_rel)
    target_path = os.path.join(target_dir, fullsha)
    if src_dir == target_dir:
      log.printerr('ticket \'%s\' already in \'%s\'' % (sha7, to_rel))
      return

    # Create the target dir, if neccessary
    if not os.path.isdir(target_dir):
      misc.mkdirs(target_dir)

    # Try to move the file into it
    try:
      # Commit the new itdb to the repo
      curr_branch = git.current_branch()
      git.change_head_branch('git-it')

      i.save(target_path)
      if os.path.isfile(src_path):
        os.remove(src_path)

      msg = 'moved ticket \'%s\' (%s --> %s)' % (sha7, rel, to_rel)
      git.command_lines('add', [target_path])
      git.command_lines('commit', ['-m', msg, src_path, target_path])
      git.change_head_branch(curr_branch)
      abs_ticket_dir = os.path.join(repo.find_root(), it.TICKET_DIR)
      git.command_lines('reset', ['HEAD', abs_ticket_dir])
      misc.rmdirs(abs_ticket_dir)

      print 'ticket \'%s\' moved to release \'%s\'' % (sha7, to_rel)
      print ''
      self.list()
    except OSError, e:
      log.printerr('could not move ticket \'%s\' to \'%s\':' % (sha7, to_rel))
      log.printerr(e)
示例#28
0
文件: gitit.py 项目: dongrote/git-it
    def edit(self, sha):
        i, rel, fullsha, match = self.get_ticket(sha)
        sha7 = misc.chop(fullsha, 7)

        # Save the contents of this ticket to a file, so it can be edited
        i.save(it.EDIT_TMP_FILE)
        timestamp1 = os.path.getmtime(it.EDIT_TMP_FILE)
        # fetch the editor command from the following sources in this order:
        #    - git config --local core.editor
        #    - git config --global core.editor
        #    - git config --system core.editor
        #    - $GIT_EDITOR
        #    - $EDITOR
        #    - /usr/bin/nano
        success = os.system('%s "%s"' % (git.get_editor(),it.EDIT_TMP_FILE)) == 0
        timestamp2 = os.path.getmtime(it.EDIT_TMP_FILE)
        if success:
            if timestamp1 < timestamp2:
                try:
                    i = ticket.create_from_file(it.EDIT_TMP_FILE, fullsha, rel)
                except ticket.MalformedTicketFieldException, e:
                    print 'Error parsing ticket: %s' % e
                    sys.exit(1)
                except ticket.MissingTicketFieldException, e:
                    print 'Error parsing ticket: %s' % e
                    sys.exit(1)

                # Now, when the edit has succesfully taken place, switch branches, commit,
                # and switch back
                curr_branch = git.current_branch()
                git.change_head_branch('git-it')
                msg = 'ticket \'%s\' edited' % sha7
                i.save()
                git.command_lines('commit', ['-m', msg, i.filename()])
                git.change_head_branch(curr_branch)
                abs_ticket_dir = os.path.join(repo.find_root(), it.TICKET_DIR)
                git.command_lines('reset', ['HEAD', abs_ticket_dir])
                misc.rmdirs(abs_ticket_dir)
                print 'ticket \'%s\' edited succesfully' % sha7
示例#29
0
文件: gitit.py 项目: dongrote/git-it
    def new(self):
        self.require_itdb()

        # Create a fresh ticket
        try:
            i = ticket.create_interactive()
        except KeyboardInterrupt:
            print ''
            print 'aborting new ticket'
            return None

        # Generate a SHA1 id
        s = sha1_constructor()
        s.update(i.__str__())
        s.update(os.getenv('LOGNAME'))
        s.update(datetime.datetime.now().__str__())
        i.id = s.hexdigest()

        # Save the ticket to disk
        i.save()
        _, ticketname = os.path.split(i.filename())
        sha7 = misc.chop(ticketname, 7)
        print 'new ticket \'%s\' saved' % sha7

        # Commit the new ticket to the 'aaa' branch
        curr_branch = git.current_branch()
        git.change_head_branch('git-it')
        git.command_lines('add', [i.filename()])
        msg = '%s added ticket \'%s\'' % (i.issuer, sha7)
        git.command_lines('commit', ['-m', msg, i.filename()])
        os.remove(i.filename())
        git.command_lines('rm', ['--cached', i.filename()])
        git.change_head_branch(curr_branch)
        abs_ticket_dir = os.path.join(repo.find_root(), it.TICKET_DIR)
        git.command_lines('reset', ['HEAD', abs_ticket_dir])
        misc.rmdirs(abs_ticket_dir)
        return i
示例#30
0
    def new(self):
        self.require_itdb()

        # Create a fresh ticket
        try:
            i = ticket.create_interactive()
        except KeyboardInterrupt:
            print ''
            print 'aborting new ticket'
            return None

        # Generate a SHA1 id
        s = sha1_constructor()
        s.update(i.__str__())
        s.update(os.getlogin())
        s.update(datetime.datetime.now().__str__())
        i.id = s.hexdigest()

        # Save the ticket to disk
        i.save()
        _, ticketname = os.path.split(i.filename())
        sha7 = misc.chop(ticketname, 7)
        print 'new ticket \'%s\' saved' % sha7

        # Commit the new ticket to the 'aaa' branch
        curr_branch = git.current_branch()
        git.change_head_branch('git-it')
        git.command_lines('add', [i.filename()])
        msg = '%s added ticket \'%s\'' % (i.issuer, sha7)
        git.command_lines('commit', ['-m', msg, i.filename()])
        os.remove(i.filename())
        git.command_lines('rm', ['--cached', i.filename()])
        git.change_head_branch(curr_branch)
        abs_ticket_dir = os.path.join(repo.find_root(), it.TICKET_DIR)
        git.command_lines('reset', ['HEAD', abs_ticket_dir])
        misc.rmdirs(abs_ticket_dir)
        return i