Browse Source

cli: fix argument parsing for pack-objects --stdout

The basename argument is unused when --stdout is used. Yet if no basename
was specified together with --stdout, the command was failing:

$ git rev-list main | dulwich pack-objects --stdout
Traceback (most recent call last):
  File "/home/stsp/dulwich/venv/bin/dulwich", line 33, in <module>
    sys.exit(load_entry_point('dulwich==0.20.50', 'console_scripts', 'dulwich')())
  File "/home/stsp/dulwich/venv/lib/python3.9/site-packages/dulwich/cli.py", line 784, in main
    return cmd_kls().run(argv[1:])
  File "/home/stsp/dulwich/venv/lib/python3.9/site-packages/dulwich/cli.py", line 533, in run
    basename = args[0]
IndexError: list index out of range
Stefan Sperling 2 years ago
parent
commit
f8e243a4c6
1 changed files with 1 additions and 1 deletions
  1. 1 1
      dulwich/cli.py

+ 1 - 1
dulwich/cli.py

@@ -529,12 +529,12 @@ class cmd_pack_objects(Command):
             print("Usage: dulwich pack-objects basename")
             sys.exit(1)
         object_ids = [line.strip() for line in sys.stdin.readlines()]
-        basename = args[0]
         if "--stdout" in opts.keys():
             packf = getattr(sys.stdout, "buffer", sys.stdout)
             idxf = None
             close = []
         else:
+            basename = args[0]
             packf = open(basename + ".pack", "wb")
             idxf = open(basename + ".idx", "wb")
             close = [packf, idxf]