def test_lookup_stacktrace_fast(self, mock_line_match, mock_files, mock_files_touched, mock_pickaxe): mock_files_touched.return_value = True traceback = self.get_traceback() self.setup_mocks(mock_files, mock_files_touched) api.lookup_stacktrace(traceback, "hash1..hash3", fast=True) self.assertEqual(1, mock_pickaxe.call_count)
def main(): usage = "git stacktrace [<options>] [<RANGE>] < stacktrace from stdin" description = "Lookup commits related to a given stacktrace" parser = argparse.ArgumentParser(usage=usage, description=description) range_group = parser.add_mutually_exclusive_group() range_group.add_argument('--since', metavar="<date1>", help='show commits ' 'more recent then a specific date (from git-log)') range_group.add_argument('range', nargs='?', help='git commit range to use') parser.add_argument('-f', '--fast', action="store_true", help='Speed things up by not running ' 'pickaxe if cannot find the file') parser.add_argument( '-p', '--path', nargs='?', help='Git path, if using --since, use this to specify which branch ' 'to run on.') parser.add_argument( '--version', action="version", version='%s version %s' % (os.path.split(sys.argv[0])[-1], git_stacktrace.__version__)) args = parser.parse_args() if args.since: git_range = api.convert_since(args.since, path=args.path) print >> sys.stderr, "commit range: %s" % git_range else: if args.range is None: print "Error: Missing range and since, must use one\n" parser.print_help() sys.exit(1) git_range = args.range if not api.valid_range(git_range): print "Found no commits in '%s'" % git_range sys.exit(1) if not select.select([sys.stdin], [], [], 0.0)[0]: raise Exception("No input found in stdin") blob = sys.stdin.readlines() traceback = api.parse_trace(blob) print traceback results = api.lookup_stacktrace(traceback, git_range, fast=args.fast) for r in results.get_sorted_results(): print "" print r if len(results.get_sorted_results()) == 0: print "No matches found"
def get_results(self): if self.trace: traceback = api.parse_trace(self.trace) return api.lookup_stacktrace(traceback, self.git_range, fast=self.fast) else: return None
def test_lookup_stacktrace_line_match(self, mock_line_match, mock_files, mock_files_touched, mock_pickaxe): mock_files_touched.return_value = True mock_line_match.return_value = True traceback = self.get_traceback() self.setup_mocks(mock_files, mock_files_touched) self.assertEqual(1, api.lookup_stacktrace(traceback, "hash1..hash3", fast=False). get_sorted_results()[0]._line_numbers_matched) self.assertEqual(3, mock_pickaxe.call_count)
def test_lookup_stacktrace_java(self, mock_line_match, mock_files, mock_files_touched, mock_pickaxe): mock_files_touched.return_value = True mock_line_match.return_value = True traceback = self.get_traceback(java=True) mock_files.return_value = ['devdaily/src/main/java/com/devdaily/tests/ExceptionTest.java'] mock_files_touched.return_value = { 'hash2': [git.GitFile('devdaily/src/main/java/com/devdaily/tests/ExceptionTest.java', 'M')]} self.assertEqual(2, api.lookup_stacktrace(traceback, "hash1..hash3", fast=False). get_sorted_results()[0]._line_numbers_matched) self.assertEqual(0, mock_pickaxe.call_count)
def main(): usage = "git stacktrace [<options>] [<RANGE>] < stacktrace from stdin" description = "Lookup commits related to a given stacktrace" parser = argparse.ArgumentParser(usage=usage, description=description) range_group = parser.add_mutually_exclusive_group() range_group.add_argument('--since', metavar="<date1>", help='show commits ' 'more recent then a specific date (from git-log)') range_group.add_argument('range', nargs='?', help='git commit range to use') parser.add_argument('-f', '--fast', action="store_true", help='Speed things up by not running ' 'pickaxe if cannot find the file') parser.add_argument('-p', '--path', nargs='?', help='Git path, if using --since, use this to specify which branch ' 'to run on.') parser.add_argument('--version', action="version", version='%s version %s' % (os.path.split(sys.argv[0])[-1], git_stacktrace.__version__)) args = parser.parse_args() if args.since: git_range = api.convert_since(args.since, path=args.path) print >> sys.stderr, "commit range: %s" % git_range else: if args.range is None: print "Error: Missing range and since, must use one\n" parser.print_help() sys.exit(1) git_range = args.range if not api.valid_range(git_range): print "Found no commits in '%s'" % git_range sys.exit(1) if not select.select([sys.stdin], [], [], 0.0)[0]: raise Exception("No input found in stdin") blob = sys.stdin.readlines() traceback = api.Traceback(blob) print "Traceback:" print traceback results = api.lookup_stacktrace(traceback, git_range, fast=args.fast) for r in results.get_sorted_results(): print "" print r if len(results.get_sorted_results()) == 0: print "No matches found"
def test_lookup_stacktrace_java(self, mock_line_match, mock_files, mock_files_touched, mock_pickaxe): mock_files_touched.return_value = True mock_line_match.return_value = True traceback = self.get_traceback(java=True) mock_files.return_value = [ 'devdaily/src/main/java/com/devdaily/tests/ExceptionTest.java' ] mock_files_touched.return_value = { 'hash2': [ git.GitFile( 'devdaily/src/main/java/com/devdaily/tests/ExceptionTest.java', 'M') ] } self.assertEqual( 2, api.lookup_stacktrace( traceback, "hash1..hash3", fast=False).get_sorted_results()[0]._line_numbers_matched) self.assertEqual(0, mock_pickaxe.call_count)
def test_lookup_stacktrace_fast(self, mock_files, mock_files_touched, mock_pickaxe): traceback = self.get_traceback() self.setup_mocks(mock_files, mock_files_touched) api.lookup_stacktrace(traceback, "hash1..hash3", fast=True) self.assertEqual(1, mock_pickaxe.call_count)
def main(): usage = "git stacktrace [<options>] [<RANGE>] < stacktrace from stdin" description = "Lookup commits related to a given stacktrace." parser = argparse.ArgumentParser(usage=usage, description=description) range_group = parser.add_mutually_exclusive_group() range_group.add_argument('--since', metavar="<date1>", help='show commits ' 'more recent than a specific date (from git-log)') range_group.add_argument('range', nargs='?', help='git commit range to use') range_group.add_argument( '--server', action="store_true", help='start a ' 'webserver to visually interact with git-stacktrace') parser.add_argument('--port', default=os.environ.get('GIT_STACKTRACE_PORT', 8080), type=int, help='Server port') parser.add_argument( '-f', '--fast', action="store_true", help='Speed things up by not running ' 'pickaxe if the file for a line of code cannot be found') parser.add_argument( '-b', '--branch', nargs='?', help='Git branch. If using --since, use this to ' 'specify which branch to run since on. Runs on current branch by default' ) parser.add_argument( '--version', action="version", version='%s version %s' % (os.path.split(sys.argv[0])[-1], git_stacktrace.__version__)) parser.add_argument('-d', '--debug', action='store_true', help='Enable debug logging') args = parser.parse_args() logging.basicConfig(format='%(name)s:%(funcName)s:%(lineno)s: %(message)s') if args.debug: logging.getLogger().setLevel(logging.DEBUG) if args.server: print("Starting httpd on port %s..." % args.port) httpd = make_server('', args.port, server.application) try: httpd.serve_forever() except KeyboardInterrupt: sys.exit(0) if args.since: git_range = api.convert_since(args.since, branch=args.branch) print("commit range: %s" % git_range, file=sys.stderr) else: if args.range is None: print("Error: Missing range and since, must use one\n") parser.print_help() sys.exit(1) git_range = args.range if not api.valid_range(git_range): print("Found no commits in '%s'" % git_range) sys.exit(1) if not select.select([sys.stdin], [], [], 0.0)[0]: raise Exception("No input found in stdin") blob = sys.stdin.readlines() traceback = api.parse_trace(blob) print(traceback) results = api.lookup_stacktrace(traceback, git_range, fast=args.fast) for r in results.get_sorted_results(): print("") print(r) if len(results.get_sorted_results()) == 0: print("No matches found")
def main(): usage = "git stacktrace [<options>] [<RANGE>] < stacktrace from stdin" description = "Lookup commits related to a given stacktrace." parser = argparse.ArgumentParser(usage=usage, description=description) range_group = parser.add_mutually_exclusive_group() range_group.add_argument('--since', metavar="<date1>", help='show commits ' 'more recent than a specific date (from git-log)') range_group.add_argument('range', nargs='?', help='git commit range to use') range_group.add_argument('--server', action="store_true", help='start a ' 'webserver to visually interact with git-stacktrace') parser.add_argument('--port', default=os.environ.get('GIT_STACKTRACE_PORT', 8080), type=int, help='Server port') parser.add_argument('-f', '--fast', action="store_true", help='Speed things up by not running ' 'pickaxe if the file for a line of code cannot be found') parser.add_argument('-b', '--branch', nargs='?', help='Git branch. If using --since, use this to ' 'specify which branch to run since on. Runs on current branch by default') parser.add_argument('--version', action="version", version='%s version %s' % (os.path.split(sys.argv[0])[-1], git_stacktrace.__version__)) parser.add_argument('-d', '--debug', action='store_true', help='Enable debug logging') args = parser.parse_args() logging.basicConfig(format='%(name)s:%(funcName)s:%(lineno)s: %(message)s') if args.debug: logging.getLogger().setLevel(logging.DEBUG) if args.server: print("Starting httpd on port %s..." % args.port) httpd = make_server('', args.port, server.application) try: httpd.serve_forever() except KeyboardInterrupt: sys.exit(0) if args.since: git_range = api.convert_since(args.since, branch=args.branch) print("commit range: %s" % git_range, file=sys.stderr) else: if args.range is None: print("Error: Missing range and since, must use one\n") parser.print_help() sys.exit(1) git_range = args.range if not api.valid_range(git_range): print("Found no commits in '%s'" % git_range) sys.exit(1) if not select.select([sys.stdin], [], [], 0.0)[0]: raise Exception("No input found in stdin") blob = sys.stdin.readlines() traceback = api.parse_trace(blob) print(traceback) results = api.lookup_stacktrace(traceback, git_range, fast=args.fast) for r in results.get_sorted_results(): print("") print(r) if len(results.get_sorted_results()) == 0: print("No matches found")