@@ -62,3 +62,97 @@ def test_push_private_repo(
6262 assert p_push .stdout .count ("Username:" ) == 2
6363 assert p_push .stdout .count ("Password:" ) == 2
6464 assert "Pushed to origin" in p_push .stdout
65+ print (p_push .stdout )
66+
67+
68+ # def test_push_branch_private_repo(
69+ # git2cpp_path, tmp_path, run_in_tmp_path, private_test_repo, commit_env_config
70+ # ):
71+ # """Test push with an explicit branch name: git2cpp push <remote> <branch>."""
72+ # branch_name = f"test-{uuid4()}"
73+
74+ # username = "abc"
75+ # password = private_test_repo["token"]
76+ # input = f"{username}\n{password}"
77+ # repo_path = tmp_path / private_test_repo["repo_name"]
78+ # url = private_test_repo["https_url"]
79+
80+ # # Clone the private repo.
81+ # clone_cmd = [git2cpp_path, "clone", url]
82+ # p_clone = subprocess.run(clone_cmd, capture_output=True, text=True, input=input)
83+ # assert p_clone.returncode == 0
84+ # assert repo_path.exists()
85+
86+ # # Create a new branch and commit on it.
87+ # checkout_cmd = [git2cpp_path, "checkout", "-b", branch_name]
88+ # p_checkout = subprocess.run(checkout_cmd, cwd=repo_path, capture_output=True, text=True)
89+ # assert p_checkout.returncode == 0
90+
91+ # (repo_path / "push_branch_file.txt").write_text("push branch test")
92+ # subprocess.run([git2cpp_path, "add", "push_branch_file.txt"], cwd=repo_path, check=True)
93+ # subprocess.run([git2cpp_path, "commit", "-m", "branch commit"], cwd=repo_path, check=True)
94+
95+ # # Switch back to main so HEAD is NOT on the branch we want to push.
96+ # subprocess.run(
97+ # [git2cpp_path, "checkout", "main"], capture_output=True, check=True, cwd=repo_path
98+ # )
99+
100+ # status_cmd = [git2cpp_path, "status"]
101+ # p_status = subprocess.run(status_cmd, cwd=repo_path, capture_output=True, text=True)
102+ # assert p_status.returncode == 0
103+ # assert "On branch main" in p_status.stdout
104+
105+ # # Push specifying the branch explicitly (HEAD is on main, not the test branch).
106+ # input = f"{username}\n{password}"
107+ # push_cmd = [git2cpp_path, "push", "origin", branch_name]
108+ # p_push = subprocess.run(push_cmd, cwd=repo_path, capture_output=True, text=True, input=input)
109+ # assert p_push.returncode == 0
110+ # assert "Pushed to origin" in p_push.stdout
111+
112+
113+ # def test_push_branches_flag_private_repo(
114+ # git2cpp_path, tmp_path, run_in_tmp_path, private_test_repo, commit_env_config
115+ # ):
116+ # """Test push --branches pushes all local branches."""
117+ # branch_a = f"test-a-{uuid4()}"
118+ # branch_b = f"test-b-{uuid4()}"
119+
120+ # username = "abc"
121+ # password = private_test_repo["token"]
122+ # input = f"{username}\n{password}"
123+ # repo_path = tmp_path / private_test_repo["repo_name"]
124+ # url = private_test_repo["https_url"]
125+
126+ # # Clone the private repo.
127+ # clone_cmd = [git2cpp_path, "clone", url]
128+ # p_clone = subprocess.run(clone_cmd, capture_output=True, text=True, input=input)
129+ # assert p_clone.returncode == 0
130+ # assert repo_path.exists()
131+
132+ # # Create two extra branches with commits.
133+ # for branch_name in [branch_a, branch_b]:
134+ # subprocess.run(
135+ # [git2cpp_path, "checkout", "-b", branch_name],
136+ # capture_output=True,
137+ # check=True,
138+ # cwd=repo_path,
139+ # )
140+ # (repo_path / f"{branch_name}.txt").write_text(f"content for {branch_name}")
141+ # subprocess.run([git2cpp_path, "add", f"{branch_name}.txt"], cwd=repo_path, check=True)
142+ # subprocess.run(
143+ # [git2cpp_path, "commit", "-m", f"commit on {branch_name}"],
144+ # cwd=repo_path,
145+ # check=True,
146+ # )
147+
148+ # # Go back to main.
149+ # subprocess.run(
150+ # [git2cpp_path, "checkout", "main"], capture_output=True, check=True, cwd=repo_path
151+ # )
152+
153+ # # Push all branches at once.
154+ # input = f"{username}\n{password}"
155+ # push_cmd = [git2cpp_path, "push", "origin", "--branches"]
156+ # p_push = subprocess.run(push_cmd, cwd=repo_path, capture_output=True, text=True, input=input)
157+ # assert p_push.returncode == 0
158+ # assert "Pushed to origin" in p_push.stdout
0 commit comments