nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: bitcoin-core/HWI
Pull request #739 (2024-05-24 16:22:46)

descriptor.py: fix parsing tr() desc with single leaf TREE
`tr()` descriptors with a single leaf TREE expression cannot be parsed currently:
```py
>>> from hwilib.descriptor import parse_descriptor
>>> b = parse_descriptor("tr(a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd,pk(669b8afcec803a0d323e9a17f3ea8e68e8abe5a278020a929adbec52421adbd0))") 
Traceback (most recent call last):
  File "/home/user/wspace/HWI/hwilib/descriptor.py", line 437, in _get_func_expr
    end = s.rindex(")")
ValueError: substring not found

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/user/wspace/HWI/hwilib/descriptor.py", line 637, in parse_descriptor
    return _parse_descriptor(desc, _ParseDescriptorContext.TOP)
  File "/home/user/wspace/HWI/hwilib/descriptor.py", line 600, in _parse_descriptor
    subscripts.append(_parse_descriptor(sarg, _ParseDescriptorContext.P2TR))
  File "/home/user/wspace/HWI/hwilib/descriptor.py", line 527, in _parse_descriptor
    func, expr = _get_func_expr(desc)
  File "/home/user/wspace/HWI/hwilib/descriptor.py", line 440, in _get_func_expr
    raise ValueError("A matching pair of parentheses cannot be found")
ValueError: A matching pair of parentheses cannot be found
```


Patch:
diff --git a/hwilib/descriptor.py b/hwilib/descriptor.py
index 311c780..4e743fd 100644
--- a/hwilib/descriptor.py
+++ b/hwilib/descriptor.py
@@ -473,6 +473,8 @@ def _get_expr(s: str) -> Tuple[str, str]:
             level -= 1
         elif level == 0 and c in [")", "}", ","]:
             break
+    else:
+        return s, ""
     return s[0:i], s[i:]
 
 def parse_pubkey(expr: str) -> Tuple['PubkeyProvider', str]:


Test patch:
diff --git a/test/test_descriptor.py b/test/test_descriptor.py
index 4df2c08..9e281a4 100755
--- a/test/test_descriptor.py
+++ b/test/test_descriptor.py
@@ -205,5 +205,15 @@ class TestDescriptor(unittest.TestCase):
         self.assertEqual(desc.depths, [1, 3, 3, 2])
         self.assertEqual(desc.to_string_no_checksum(), d)
 
+        d = "tr(a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd,pk(669b8afcec803a0d323e9a17f3ea8e68e8abe5a278020a929adbec52421adbd0))"
+        desc = parse_descriptor(d)
+        self.assertTrue(isinstance(desc, TRDescriptor))
+        self.assertEqual(len(desc.subdescriptors), 1)
+        self.assertEqual(desc.pubkeys[0].pubkey, "a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd")
+        self.assertEqual(desc.depths, [0])
+        self.assertEqual(desc.subdescriptors[0].pubkeys[0].pubkey, "669b8afcec803a0d323e9a17f3ea8e68e8abe5a278020a929adbec52421adbd0")
+        self.assertEqual(desc.to_string_no_checksum(), d)
+
+
 if __name__ == "__main__":
     unittest.main()
Repository: VirtusLab/git-machete
Pull request #577 (2022-07-12 12:51:53)

Issue #573: Prioritise `origin` remote when inferring remote 


Patch:
diff --git a/git_machete/client.py b/git_machete/client.py
index 441575b..1e38f48 100644
--- a/git_machete/client.py
+++ b/git_machete/client.py
@@ -2058,6 +2058,12 @@ class MacheteClient:
                     'If that is the case, you can provide repository information explicitly, via these 3 git config keys: '
                     '`machete.github.{remote,organization,repository}`\n'))
 
+        if len(remote_and_github_org_and_repo) == 1:
+            return remote_and_github_org_and_repo[list(remote_and_github_org_and_repo.keys())[0]]
+
+        if 'origin' in remote_and_github_org_and_repo:
+            return remote_and_github_org_and_repo['origin']
+
         if len(remote_and_github_org_and_repo) > 1 and branch_used_for_tracking_data is not None:
             remote_for_fetching_of_branch = self.__git.get_combined_remote_for_fetching_of_branch(
                 branch=branch_used_for_tracking_data,
@@ -2065,12 +2071,6 @@ class MacheteClient:
             if remote_for_fetching_of_branch is not None:
                 return remote_and_github_org_and_repo[remote_for_fetching_of_branch]
 
-        if len(remote_and_github_org_and_repo) == 1:
-            return remote_and_github_org_and_repo[list(remote_and_github_org_and_repo.keys())[0]]
-
-        if 'origin' in remote_and_github_org_and_repo:
-            return remote_and_github_org_and_repo['origin']
-
         raise MacheteException(
             f'Multiple non-origin remotes correspond to GitHub in this repository: '
             f'{", ".join(remote_and_github_org_and_repo.keys())} -> aborting. \n'


Test patch:
diff --git a/tests/test_github.py b/tests/test_github.py
index 31f5414..a3a7cf5 100644
--- a/tests/test_github.py
+++ b/tests/test_github.py
@@ -775,6 +775,26 @@ class TestGithub:
             indent=''
         )
 
+        # branch feature_3 present in only one remote: origin_2 with tracking data, origin remote present - takes priority
+        (
+            self.repo_sandbox.add_remote('origin', self.repo_sandbox.remote_path)
+                .check_out('feature_3')
+                .new_branch('feature_5')
+                .commit('introduce feature 5')
+                .push(remote='origin_2')
+        )
+
+        expected_result = """
+        Added branch `feature_5` onto `feature_3`
+        Fetching origin...
+        Creating a PR from `feature_5` to `feature_3`... OK, see www.github.com
+        """
+        assert_command(
+            ['github', 'create-pr'],
+            expected_result,
+            indent=''
+        )
+
     git_api_state_for_test_checkout_prs = MockGitHubAPIState(
         [
             {