Dulwich.io dulwich / 9040b39
Fix pushing of new branches from porcelain.push. Fixes #788 Jelmer Vernooij 10 days ago
3 changed file(s) with 59 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
11
22 * Add a ``RefsContainer.watch`` interface.
33 (Jelmer Vernooij, #751)
4
5 * Fix pushing of new branches from porcelain.push.
6 (Jelmer Vernooij, #788)
47
58 0.20.5 2020-06-22
69
974974 new_refs[rh] = ZERO_SHA
975975 remote_changed_refs[rh] = None
976976 else:
977 if not force_ref:
978 check_diverged(r, refs[rh], r.refs[lh])
979 new_refs[rh] = r.refs[lh]
980 remote_changed_refs[rh] = r.refs[lh]
977 try:
978 localsha = r.refs[lh]
979 except KeyError:
980 raise Error(
981 'No valid ref %s in local repository' % lh)
982 if not force_ref and rh in refs:
983 check_diverged(r, refs[rh], localsha)
984 new_refs[rh] = localsha
985 remote_changed_refs[rh] = localsha
981986 return new_refs
982987
983988 err_encoding = getattr(errstream, 'encoding', None) or DEFAULT_ENCODING
923923 self.repo[b'refs/heads/foo'].tree))[0]
924924 self.assertEqual(os.path.basename(fullpath),
925925 change.new.path.decode('ascii'))
926
927 def test_local_missing(self):
928 """Pushing a new branch."""
929 outstream = BytesIO()
930 errstream = BytesIO()
931
932 # Setup target repo cloned from temp test repo
933 clone_path = tempfile.mkdtemp()
934 self.addCleanup(shutil.rmtree, clone_path)
935 target_repo = porcelain.init(clone_path)
936 target_repo.close()
937
938 self.assertRaises(
939 porcelain.Error,
940 porcelain.push, self.repo, clone_path,
941 b"HEAD:refs/heads/master",
942 outstream=outstream, errstream=errstream)
943
944 def test_new(self):
945 """Pushing a new branch."""
946 outstream = BytesIO()
947 errstream = BytesIO()
948
949 # Setup target repo cloned from temp test repo
950 clone_path = tempfile.mkdtemp()
951 self.addCleanup(shutil.rmtree, clone_path)
952 target_repo = porcelain.init(clone_path)
953 target_repo.close()
954
955 # create a second file to be pushed back to origin
956 handle, fullpath = tempfile.mkstemp(dir=clone_path)
957 os.close(handle)
958 porcelain.add(repo=clone_path, paths=[fullpath])
959 new_id = porcelain.commit(
960 repo=self.repo, message=b'push',
961 author=b'author <email>',
962 committer=b'committer <email>')
963
964 # Push to the remote
965 porcelain.push(self.repo, clone_path, b"HEAD:refs/heads/master",
966 outstream=outstream, errstream=errstream)
967
968 with Repo(clone_path) as r_clone:
969 self.assertEqual({
970 b'HEAD': new_id,
971 b'refs/heads/master': new_id,
972 }, r_clone.get_refs())
926973
927974 def test_delete(self):
928975 """Basic test of porcelain push, removing a branch.