@@ -164,41 +164,115 @@ def test_race(tmpdir, local_docs_ghp, remote, run, urls, give_up):
164164 assert actual == 'Orphaned branch for HTML docs.changed'
165165
166166
167- def test_second_remote (tmpdir , local_docs_ghp , run , urls ):
168- """Test pushing to a non-origin remote.
167+ def test_different_push (tmpdir , local_docs_ghp , run , urls ):
168+ """Test pushing to a different remote URL .
169169
170170 :param tmpdir: pytest fixture.
171171 :param local_docs_ghp: conftest fixture.
172172 :param run: conftest fixture.
173173 :param urls: conftest fixture.
174174 """
175+ remote2 = tmpdir .ensure_dir ('remote2' )
176+ run (local_docs_ghp , ['git' , 'remote' , 'set-url' , 'origin' , '--push' , remote2 ])
177+
175178 # Error out because remote2 doesn't exist yet.
176179 with pytest .raises (CalledProcessError ) as exc :
177- run (local_docs_ghp , ['sphinx-versioning' , 'push' , '.' , 'gh-pages' , '.' , '-P' , 'remote2' ])
180+ run (local_docs_ghp , ['sphinx-versioning' , 'push' , '.' , 'gh-pages' , '.' ])
178181 assert 'Traceback' not in exc .value .output
179182 assert 'Failed to push to remote.' in exc .value .output
180- assert "fatal: 'remote2' does not appear to be a git repository" in exc .value .output
183+ assert "remote2' does not appear to be a git repository" in exc .value .output
184+
185+ # Create remote2.
186+ run (remote2 , ['git' , 'init' , '--bare' ])
187+
188+ # Run again.
189+ output = run (local_docs_ghp , ['sphinx-versioning' , 'push' , '.' , 'gh-pages' , '.' ])
190+ assert 'Traceback' not in output
191+ assert 'Successfully pushed to remote repository.' in output
192+
193+ # Check files.
194+ run (local_docs_ghp , ['git' , 'fetch' , 'origin' ])
195+ run (local_docs_ghp , ['git' , 'checkout' , 'origin/gh-pages' ])
196+ assert not local_docs_ghp .join ('contents.html' ).check ()
197+ assert not local_docs_ghp .join ('master' ).check ()
198+ run (local_docs_ghp , ['git' , 'remote' , 'add' , 'remote2' , remote2 ])
199+ run (local_docs_ghp , ['git' , 'fetch' , 'remote2' ])
200+ run (local_docs_ghp , ['git' , 'checkout' , 'remote2/gh-pages' ])
201+ urls (local_docs_ghp .join ('contents.html' ), ['<li><a href="master/contents.html">master</a></li>' ])
202+ urls (local_docs_ghp .join ('master' , 'contents.html' ), ['<li><a href="contents.html">master</a></li>' ])
203+
204+
205+ @pytest .mark .parametrize ('remove' , [True , False ])
206+ def test_second_remote (tmpdir , local_docs_ghp , run , urls , remove ):
207+ """Test pushing to a non-origin remote without the original remote having the destination branch.
208+
209+ :param tmpdir: pytest fixture.
210+ :param local_docs_ghp: conftest fixture.
211+ :param run: conftest fixture.
212+ :param urls: conftest fixture.
213+ :param bool remove: Remove gh-pages from origin.
214+ """
215+ if remove :
216+ run (local_docs_ghp , ['git' , 'push' , 'origin' , '--delete' , 'gh-pages' ])
181217
182218 # Create remote2.
183219 remote2 = tmpdir .ensure_dir ('remote2' )
184220 run (remote2 , ['git' , 'init' , '--bare' ])
221+ local2 = tmpdir .ensure_dir ('local2' )
222+ run (local2 , ['git' , 'clone' , remote2 , '.' ])
223+ run (local2 , ['git' , 'checkout' , '-b' , 'gh-pages' ])
224+ local2 .ensure ('README' )
225+ run (local2 , ['git' , 'add' , 'README' ])
226+ run (local2 , ['git' , 'commit' , '-m' , 'Initial commit.' ])
227+ run (local2 , ['git' , 'push' , 'origin' , 'gh-pages' ])
185228 run (local_docs_ghp , ['git' , 'remote' , 'add' , 'remote2' , remote2 ])
186- run (local_docs_ghp , ['git' , 'push' , 'remote2' , 'gh-pages' ])
229+ run (local_docs_ghp , ['git' , 'fetch' , 'remote2' ])
230+
231+ # Run.
232+ output = run (local_docs_ghp , ['sphinx-versioning' , 'push' , '.' , 'gh-pages' , '.' , '-P' , 'remote2' ])
233+ assert 'Traceback' not in output
234+ assert 'Successfully pushed to remote repository.' in output
235+
236+ # Check files.
237+ run (local_docs_ghp , ['git' , 'fetch' , 'remote2' ])
238+ run (local_docs_ghp , ['git' , 'checkout' , 'remote2/gh-pages' ])
239+ urls (local_docs_ghp .join ('contents.html' ), ['<li><a href="master/contents.html">master</a></li>' ])
240+ urls (local_docs_ghp .join ('master' , 'contents.html' ), ['<li><a href="contents.html">master</a></li>' ])
241+ if remove :
242+ with pytest .raises (CalledProcessError ) as exc :
243+ run (local_docs_ghp , ['git' , 'checkout' , 'origin/gh-pages' ])
244+ assert "origin/gh-pages' did not match any file(s) known to git." in exc .value .output
245+ else :
246+ run (local_docs_ghp , ['git' , 'checkout' , 'origin/gh-pages' ])
247+ run (local_docs_ghp , ['git' , 'pull' , 'origin' , 'gh-pages' ])
248+ assert not local_docs_ghp .join ('contents.html' ).check ()
249+ assert not local_docs_ghp .join ('master' ).check ()
187250
188251 # Run again.
252+ run (local_docs_ghp , ['git' , 'checkout' , 'master' ])
253+ local_docs_ghp .join ('contents.rst' ).write ('\n New Line Added\n ' , mode = 'a' )
254+ run (local_docs_ghp , ['git' , 'commit' , '-am' , 'Adding new line.' ])
255+ run (local_docs_ghp , ['git' , 'push' , 'origin' , 'master' ])
189256 output = run (local_docs_ghp , ['sphinx-versioning' , 'push' , '.' , 'gh-pages' , '.' , '-P' , 'remote2' ])
190257 assert 'Traceback' not in output
191258 assert 'Successfully pushed to remote repository.' in output
192259
193260 # Check files.
261+ run (local_docs_ghp , ['git' , 'fetch' , 'remote2' ])
194262 run (local_docs_ghp , ['git' , 'checkout' , 'remote2/gh-pages' ])
195- run (local_docs_ghp , ['git' , 'pull' , 'remote2' , 'gh-pages' ])
196263 urls (local_docs_ghp .join ('contents.html' ), ['<li><a href="master/contents.html">master</a></li>' ])
197264 urls (local_docs_ghp .join ('master' , 'contents.html' ), ['<li><a href="contents.html">master</a></li>' ])
198- run (local_docs_ghp , ['git' , 'checkout' , 'origin/gh-pages' ])
199- run (local_docs_ghp , ['git' , 'pull' , 'origin' , 'gh-pages' ])
200- assert not local_docs_ghp .join ('contents.html' ).check ()
201- assert not local_docs_ghp .join ('master' ).check ()
265+ contents = local_docs_ghp .join ('contents.html' ).read ()
266+ assert 'New Line Added' in contents
267+ if remove :
268+ with pytest .raises (CalledProcessError ) as exc :
269+ run (local_docs_ghp , ['git' , 'checkout' , 'origin/gh-pages' ])
270+ assert "origin/gh-pages' did not match any file(s) known to git." in exc .value .output
271+ else :
272+ run (local_docs_ghp , ['git' , 'checkout' , 'origin/gh-pages' ])
273+ run (local_docs_ghp , ['git' , 'pull' , 'origin' , 'gh-pages' ])
274+ assert not local_docs_ghp .join ('contents.html' ).check ()
275+ assert not local_docs_ghp .join ('master' ).check ()
202276
203277
204278def test_error_clone_failure (local_docs , run ):
0 commit comments