Skip to content

SWE-agent takes a GitHub issue and tries to automatically fix it, using your LM of choice. It can also be employed for offensive cybersecurity or competitive coding challenges. [NeurIPS 2024]

Docs: Add verbose notes about avoiding formatting merge conflicts (#448)

Kilian Lieret80a1d30899ed
diff --git a/docs/dev/contribute.md b/docs/dev/contribute.md
index d4eb8449..6d74db67 100644
--- a/docs/dev/contribute.md
+++ b/docs/dev/contribute.md
@@ -57,7 +57,7 @@ pytest -m "not slow"
## Tips for pull requests
-* If you see a lot of formatting-related merge conflicts, please see [below](#formatting-merge-conflicts).
+* If you see a lot of formatting-related merge conflicts, please see [here](formatting_conflicts.md).
* Please open separate PRs for separate issues. This makes it easier to incorporate part of your changes.
* It might be good to open an issue and discuss first before investing time on an experimental feature.
* Don't know where to get started? Look for issues marked [👋 good first issue][gfi] or [🙏 help wanted][help_wanted]
@@ -70,10 +70,6 @@ pytest -m "not slow"
[gfi]: https://github.com/princeton-nlp/SWE-agent/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc+label%3A%22%F0%9F%91%8B+good+first+issue%22+
[help_wanted]: https://github.com/princeton-nlp/SWE-agent/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc+label%3A%22%F0%9F%99%8F+help+wanted%22
-## Merge conflicts due to formatting <a name="formatting-merge-conflicts"></a>
-
-Information will be added later today.
-
## Building the documentation
Simply run
@@ -84,3 +80,5 @@ mkdocs serve
```
and point your browser to port 8000 or click one of the links in the output.
+
+{% include-markdown "../_footer.md" %}
\ No newline at end of file
diff --git a/docs/dev/formatting_conflicts.md b/docs/dev/formatting_conflicts.md
new file mode 100644
index 00000000..94515c96
--- /dev/null
+++ b/docs/dev/formatting_conflicts.md
@@ -0,0 +1,65 @@
+On May 28th, 2024, we introduced automated formatting with `ruff-format` and `pre-commit`. This changed almost every file in the project.
+If you forked or branched off before these changes and now try to synchronize your fork/branch with `princeton-nlp/SWE-agent:main`, you will
+see a lot of merge conflicts.
+
+To solve this, you need to apply the same formatting to your code. Here's how you can do it.
+
+First let's add the official remote (if it exists, you've probably already added it and you can ignore the warning).
+
+```bash
+git remote add upstream https://github.com/princeton-nlp/SWE-agent.git
+git fetch upstream
+```
+
+Now, you need the updated `pyproject.toml` and `.pre-commit-config.yaml` files.
+We can get them from `princeton-nlp/SWE-agent:main`:
+
+```bash
+git checkout upstream/main -- .pre-commit-config.yaml pyproject.toml
+git commit -m "Update formatting instructions" --no-verify
+```
+
+Let's assume that your changes are on branch `FEATURE_BRANCH`, for example, if you've committed to `main`:
+
+```bash
+export FEATURE_BRANCH="main"
+```
+
+Next we create a copy of this branch (so we don't further modify it):
+
+```bash
+git branch "${FEATURE_BRANCH}" "${FEATURE_BRANCH}_REBASED"
+```
+
+And now comes the tricky bit: We rebase your changes on top of `upstream/mean`, while applying
+the formatting fixes at every step:
+
+```bash
+git rebase upstream/main "${FEATURE_BRANCH}_REBASED" \
+ -Xtheirs \
+ --exec 'git reset --soft HEAD^; pre-commit run; pipx run ruff check --fix --unsafe-fixes; git add -u; git commit -C HEAD@{1} --no-verify'
+```
+
+!!! note "Understanding the last command"
+ Here's what is happening:
+
+ * `git rebase upstream/main "${FEATURE_BRANCH}_REBASED"`
+ applies every commit from `"${FEATURE_BRANCH}_REBASED"` on top of `upstream/main`.
+ * `-Xtheirs` tells git to always take _your_ changes for merge conflicts
+ (rather than the format changes).
+ * After every commit, the command from `--exec` is being called.
+ * `git reset --soft HEAD^` undos the `git commit` action (while leaving the
+ changes staged),
+ * then we apply the formatting, and
+ * finally we commit the
+ formatted changes again.
+
+!!! tip "Still merge conflicts?"
+ It's possible that there are non-formatting-related merge conflicts that you are encountering.
+ In this case, `git rebase` will stop every time it cannot resolve the conflict.
+ Simply fix the merge conflicts as you would normally do (edit the file, commit once done),
+ and then run `git rebase --continue`.
+
+You can now open a PR from `${FEATURE_BRANCH}_REBASED` or make it your new default branch.
+
+{% include-markdown "../_footer.md" %}
\ No newline at end of file
diff --git a/docs/overrides/main.html b/docs/overrides/main.html
new file mode 100644
index 00000000..2ec56551
--- /dev/null
+++ b/docs/overrides/main.html
@@ -0,0 +1,5 @@
+{% extends "base.html" %}
+
+{% block announce %}
+Forked/branched off of SWE-agent? Please use our latest formatting to resolve merge conflicts. See <a href="/dev/formatting_conflicts">here</a> for details.
+{% endblock %}
diff --git a/mkdocs.yml b/mkdocs.yml
index 2d395709..7bfeebe0 100644
--- a/mkdocs.yml
+++ b/mkdocs.yml
@@ -1,6 +1,7 @@
site_name: SWE-agent documentation
theme:
name: material
+ custom_dir: docs/overrides
icon:
repo: fontawesome/brands/github
logo: assets/swe-agent.svg
@@ -29,6 +30,8 @@ theme:
- navigation.footer
- content.code.copy
- content.footnote.tooltips
+ - header.autohide
+ - announce.dismiss
markdown_extensions:
- admonition
- pymdownx.details
@@ -65,6 +68,7 @@ nav:
- "Environment variables": "config/env.md"
- Development:
- "Contribution guide": "dev/contribute.md"
+ - "Formatting conflicts": "dev/formatting_conflicts.md"
- "Code structure": "dev/code_structure.md"
plugins:
- glightbox