Skip to content

Commit 8459a5a

Browse files
author
Michelle Tilley
authored
Merge pull request git-school#79 from git-school/mkt-fix-pushing-weirdnes
Fix pushing weirdness
2 parents 0097872 + a58711b commit 8459a5a

File tree

1 file changed

+9
-18
lines changed

1 file changed

+9
-18
lines changed

js/controlbox.js

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,7 @@ function(_yargs, d3, demos) {
742742
localCommit, remoteCommit,
743743
findCommitsToPush,
744744
isCommonCommit,
745+
idsToPush = [],
745746
toPush = [];
746747

747748
if (remoteName === 'history') {
@@ -775,26 +776,16 @@ function(_yargs, d3, demos) {
775776
remoteCommit = remote.getCommit(remoteRef);
776777

777778
findCommitsToPush = function findCommitsToPush(localCommit) {
778-
var commitToPush,
779-
isCommonCommit = remote.getCommit(localCommit.id) !== null;
780-
781-
while (!isCommonCommit) {
782-
commitToPush = {
783-
id: localCommit.id,
784-
parent: localCommit.parent,
785-
tags: []
786-
};
787-
788-
if (typeof localCommit.parent2 === 'string') {
789-
commitToPush.parent2 = localCommit.parent2;
790-
findCommitsToPush(local.getCommit(localCommit.parent2));
791-
}
779+
var alreadyPushed = remote.getCommit(localCommit.id) !== null
780+
if (!alreadyPushed && idsToPush.indexOf(localCommit.id) === -1) {
781+
idsToPush.push(localCommit.id)
782+
783+
toPush.push(Object.assign({}, localCommit, {tags: []}))
792784

793-
toPush.unshift(commitToPush);
794-
localCommit = local.getCommit(localCommit.parent);
795-
isCommonCommit = remote.getCommit(localCommit.id) !== null;
785+
localCommit.parent && findCommitsToPush(local.getCommit(localCommit.parent))
786+
localCommit.parent2 && findCommitsToPush(local.getCommit(localCommit.parent2))
796787
}
797-
};
788+
}
798789

799790
// push to an existing branch on the remote
800791
if (remoteCommit && remote.branches.indexOf(remoteRef) > -1) {

0 commit comments

Comments
 (0)