Browse Source

Merge pull request #1105 from stspdotname/fix-pack-objects-cli

Fix pack objects cli
Jelmer Vernooij 2 years ago
parent
commit
b6b4296b29
2 changed files with 6 additions and 6 deletions
  1. 5 5
      dulwich/cli.py
  2. 1 1
      dulwich/objects.py

+ 5 - 5
dulwich/cli.py

@@ -525,18 +525,18 @@ class cmd_pack_objects(Command):
     def run(self, args):
         opts, args = getopt(args, "", ["stdout"])
         opts = dict(opts)
-        if len(args) < 1 and "--stdout" not in args:
+        if len(args) < 1 and "--stdout" not in opts.keys():
             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:
+        if "--stdout" in opts.keys():
             packf = getattr(sys.stdout, "buffer", sys.stdout)
             idxf = None
             close = []
         else:
-            packf = open(basename + ".pack", "w")
-            idxf = open(basename + ".idx", "w")
+            basename = args[0]
+            packf = open(basename + ".pack", "wb")
+            idxf = open(basename + ".idx", "wb")
             close = [packf, idxf]
         porcelain.pack_objects(".", object_ids, packf, idxf)
         for f in close:

+ 1 - 1
dulwich/objects.py

@@ -135,7 +135,7 @@ def hex_to_filename(path, hex):
     # os.path.join accepts bytes or unicode, but all args must be of the same
     # type. Make sure that hex which is expected to be bytes, is the same type
     # as path.
-    if getattr(path, "encode", None) is not None:
+    if type(path) != type(hex) and getattr(path, "encode", None) is not None:
         hex = hex.decode("ascii")
     dir = hex[:2]
     file = hex[2:]