浏览代码

Fix tests (#1572)

Jelmer Vernooij 2 月之前
父节点
当前提交
d277472101
共有 5 个文件被更改,包括 22 次插入5 次删除
  1. 1 1
      dulwich/cli.py
  2. 15 2
      dulwich/porcelain.py
  3. 2 0
      tests/__init__.py
  4. 2 1
      tests/test_cli_merge.py
  5. 2 1
      tests/test_porcelain_merge.py

+ 1 - 1
dulwich/cli.py

@@ -873,7 +873,7 @@ class cmd_merge(Command):
                     "\nAutomatic merge failed; fix conflicts and then commit the result."
                 )
                 sys.exit(1)
-            elif merge_commit_id is None:
+            elif merge_commit_id is None and not args.no_commit:
                 print("Already up to date.")
             elif args.no_commit:
                 print("Automatic merge successful; not committing as requested.")

+ 15 - 2
dulwich/porcelain.py

@@ -596,18 +596,26 @@ def add(repo=".", paths=None):
         repo_path = Path(r.path).resolve()
         ignore_manager = IgnoreFilterManager.from_repo(r)
         if not paths:
+            cwd = Path(os.getcwd()).resolve()
             paths = list(
                 get_untracked_paths(
-                    str(Path(os.getcwd()).resolve()),
+                    str(cwd),
                     str(repo_path),
                     r.open_index(),
                 )
             )
+            # If we're in a subdirectory, adjust paths to be relative to repo root
+            if cwd != repo_path:
+                cwd_relative_to_repo = cwd.relative_to(repo_path)
+                paths = [str(cwd_relative_to_repo / p) for p in paths]
         relpaths = []
         if not isinstance(paths, list):
             paths = [paths]
         for p in paths:
             path = Path(p)
+            if not path.is_absolute():
+                # Make relative paths relative to the repo directory
+                path = repo_path / path
             relpath = str(path.resolve().relative_to(repo_path))
             # FIXME: Support patterns
             if path.is_dir():
@@ -2592,6 +2600,11 @@ def _do_merge(
     # Use the first merge base
     base_commit_id = merge_bases[0]
 
+    # Check if we're trying to merge the same commit
+    if head_commit_id == merge_commit_id:
+        # Already up to date
+        return (None, [])
+
     # Check for fast-forward
     if base_commit_id == head_commit_id and not no_ff:
         # Fast-forward merge
@@ -2686,7 +2699,7 @@ def merge(
     with open_repo_closing(repo) as r:
         # Parse the commit to merge
         try:
-            merge_commit_id = parse_commit(r, committish)
+            merge_commit_id = parse_commit(r, committish).id
         except KeyError:
             raise Error(f"Cannot find commit '{committish}'")
 

+ 2 - 0
tests/__init__.py

@@ -118,6 +118,7 @@ def self_test_suite():
         "archive",
         "blackbox",
         "bundle",
+        "cli_merge",
         "client",
         "cloud_gcs",
         "commit_graph",
@@ -145,6 +146,7 @@ def self_test_suite():
         "pack",
         "patch",
         "porcelain",
+        "porcelain_merge",
         "protocol",
         "reflog",
         "refs",

+ 2 - 1
tests/test_cli_merge.py

@@ -29,7 +29,8 @@ from unittest.mock import patch
 
 from dulwich import porcelain
 from dulwich.cli import main
-from dulwich.tests import TestCase
+
+from . import TestCase
 
 
 class CLIMergeTests(TestCase):

+ 2 - 1
tests/test_porcelain_merge.py

@@ -27,7 +27,8 @@ import unittest
 
 from dulwich import porcelain
 from dulwich.repo import Repo
-from dulwich.tests import TestCase
+
+from . import TestCase
 
 
 class PorcelainMergeTests(TestCase):