Skip to content

Commit

Permalink
merge: Fix errors when setting author/committer from env vars
Browse files Browse the repository at this point in the history
  • Loading branch information
craigds committed Nov 18, 2024
1 parent 60b702d commit f52ce3e
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
6 changes: 3 additions & 3 deletions kart/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ def do_merge(
merge_tree_id = index.write_tree(repo, write_merged_index_flags(repo))
L.debug(f"Merge tree: {merge_tree_id}")

user = repo.default_signature
if not message:
message = get_commit_message(
merge_context,
Expand All @@ -170,10 +169,11 @@ def do_merge(
launch_editor=launch_editor,
quiet=quiet,
)

merge_commit_id = repo.create_commit(
ours.reference.name,
user,
user,
repo.author_signature(),
repo.committer_signature(),
message,
merge_tree_id,
[ours.id, theirs.id],
Expand Down
44 changes: 44 additions & 0 deletions tests/test_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,3 +525,47 @@ def test_merge_ancestor_json(data_archive, cli_runner):

assert output["noOp"]
assert output["message"] is None


def test_merge_signatures_from_environment(
data_archive, cli_runner, tmp_path_factory, monkeypatch
):
with data_archive("points") as repo_path:
r = cli_runner.invoke(["branch", "b1", "main"])
assert r.exit_code == 0, r.stderr

# make a commit
FEATURE = {
"fid": 1168,
"geom": "0101000000FFA26275E7FA65405CAC5D37987E42C0",
"t50_fid": 2427412,
"name_ascii": "Tairua",
"macronated": "N",
"name": "Tairua",
}
repo = KartRepo(repo_path)
b1_commit = _apply_features(
repo,
ref="refs/heads/b1",
features=[{"-": FEATURE, "+": {**FEATURE, "name": "b1"}}],
)

# override the `git_user_config` fixture from conftest.py
# so that there's no `user.name` or `user.email` in the `.gitconfig` file
home = tmp_path_factory.mktemp("home")
monkeypatch.setenv("HOME", str(home))

# now merge the branch into main
monkeypatch.setenv("GIT_AUTHOR_NAME", "author")
monkeypatch.setenv("GIT_AUTHOR_EMAIL", "[email protected]")
monkeypatch.setenv("GIT_COMMITTER_NAME", "committer")
monkeypatch.setenv("GIT_COMMITTER_EMAIL", "[email protected]")
r = cli_runner.invoke(
["merge", "--output-format=json", "--no-ff", "b1", "--message=m"]
)
assert r.exit_code == 0, r.stderr

assert repo.head_commit.author.name == "author"
assert repo.head_commit.author.email == "[email protected]"
assert repo.head_commit.committer.name == "committer"
assert repo.head_commit.committer.email == "[email protected]"

0 comments on commit f52ce3e

Please sign in to comment.