fix(gtea): test_git_push: auto_init repo + direct URL push
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
Empty-repo HTTPS push with git clone exits 0 but silently fails (remote branch creation on an empty clone is unreliable). Fix: - Create repo with auto_init=True + default_branch=main (initial commit present) - Clone into a non-existing subdir (git clone must target non-existing path) - Push via explicit cred_url (bypasses remote config; no tracking needed) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@ -70,18 +70,18 @@ def test_git_push(live_app):
|
||||
user, password = admin_creds(live_app)
|
||||
repo_name = "ci-test-push"
|
||||
|
||||
# 1. Create test repo
|
||||
# 1. Create test repo (auto_init adds an initial commit so the branch exists)
|
||||
status, body = _api(
|
||||
live_app, "/user/repos", method="POST",
|
||||
body={"name": repo_name, "private": False, "auto_init": False},
|
||||
body={"name": repo_name, "private": False, "auto_init": True, "default_branch": "main"},
|
||||
user=user, password=password,
|
||||
)
|
||||
assert status == 201, f"repo create HTTP {status}: {body}"
|
||||
# Embed credentials directly in the URL so clone + push both work without
|
||||
# a separate credential helper. Password is a 32-char hex string (URL-safe).
|
||||
# Embed credentials directly in the URL (password is 32-char hex, URL-safe).
|
||||
cred_url = f"https://{user}:{password}@{live_app}/{user}/{repo_name}.git"
|
||||
|
||||
tmpdir = tempfile.mkdtemp(prefix="ccci-gitea-push-")
|
||||
tmpdir = tempfile.mkdtemp(prefix="ccci-gitea-push-parent-")
|
||||
repo_dir = os.path.join(tmpdir, "repo")
|
||||
try:
|
||||
git_env = {
|
||||
"GIT_AUTHOR_NAME": "CI Test Bot",
|
||||
@ -92,19 +92,18 @@ def test_git_push(live_app):
|
||||
"GIT_TERMINAL_PROMPT": "0",
|
||||
}
|
||||
|
||||
# 2. Clone (empty repo)
|
||||
_run_git(["clone", cred_url, tmpdir], cwd="/tmp", env=git_env)
|
||||
_run_git(["checkout", "-b", "main"], cwd=tmpdir, env=git_env)
|
||||
# 2. Clone into a fresh subdirectory (git clone must target a non-existing path)
|
||||
_run_git(["clone", cred_url, repo_dir], cwd="/tmp", env=git_env)
|
||||
|
||||
# 3. Commit a file
|
||||
readme = os.path.join(tmpdir, "README.md")
|
||||
# 3. Commit a new file on top of the initial commit
|
||||
readme = os.path.join(repo_dir, "ci-test.txt")
|
||||
with open(readme, "w") as f:
|
||||
f.write(f"# {repo_name}\n\nAutomated ci push test.\n")
|
||||
_run_git(["add", "README.md"], cwd=tmpdir, env=git_env)
|
||||
_run_git(["commit", "-m", "test: automated push test"], cwd=tmpdir, env=git_env)
|
||||
_run_git(["add", "ci-test.txt"], cwd=repo_dir, env=git_env)
|
||||
_run_git(["commit", "-m", "test: automated push test"], cwd=repo_dir, env=git_env)
|
||||
|
||||
# 4. Push
|
||||
_run_git(["push", "origin", "HEAD:main"], cwd=tmpdir, env=git_env)
|
||||
# 4. Push via explicit URL so credentials are applied regardless of remote config
|
||||
_run_git(["push", cred_url, "HEAD:refs/heads/main"], cwd=repo_dir, env=git_env)
|
||||
|
||||
# 5. Verify commit landed via API
|
||||
status, commits = _api(
|
||||
@ -117,6 +116,6 @@ def test_git_push(live_app):
|
||||
f"Unexpected commit message: {commit_msg!r}"
|
||||
)
|
||||
finally:
|
||||
shutil.rmtree(tmpdir, ignore_errors=True)
|
||||
shutil.rmtree(tmpdir, ignore_errors=True) # removes parent + repo subdir
|
||||
# 6. Cleanup — delete the test repo
|
||||
_api(live_app, f"/repos/{user}/{repo_name}", method="DELETE", user=user, password=password)
|
||||
|
||||
Reference in New Issue
Block a user