@@ -1070,7 +1070,7 @@ func checkFastForwardUpdate(s storer.EncodedObjectStorer, remoteRefs storer.Refe
10701070 return fmt .Errorf ("non-fast-forward update: %s" , cmd .Name .String ())
10711071 }
10721072
1073- ff , err := isFastForward (s , cmd .Old , cmd .New )
1073+ ff , err := isFastForward (s , cmd .Old , cmd .New , nil )
10741074 if err != nil {
10751075 return err
10761076 }
@@ -1082,14 +1082,28 @@ func checkFastForwardUpdate(s storer.EncodedObjectStorer, remoteRefs storer.Refe
10821082 return nil
10831083}
10841084
1085- func isFastForward (s storer.EncodedObjectStorer , old , new plumbing.Hash ) (bool , error ) {
1085+ func isFastForward (s storer.EncodedObjectStorer , old , new plumbing.Hash , earliestShallow * plumbing. Hash ) (bool , error ) {
10861086 c , err := object .GetCommit (s , new )
10871087 if err != nil {
10881088 return false , err
10891089 }
10901090
1091+ parentsToIgnore := []plumbing.Hash {}
1092+ if earliestShallow != nil {
1093+ earliestCommit , err := object .GetCommit (s , * earliestShallow )
1094+ if err != nil {
1095+ return false , err
1096+ }
1097+
1098+ parentsToIgnore = earliestCommit .ParentHashes
1099+ }
1100+
10911101 found := false
1092- iter := object .NewCommitPreorderIter (c , nil , nil )
1102+ // stop iterating at the earlist shallow commit, ignoring its parents
1103+ // note: when pull depth is smaller than the number of new changes on the remote, this fails due to missing parents.
1104+ // as far as i can tell, without the commits in-between the shallow pull and the earliest shallow, there's no
1105+ // real way of telling whether it will be a fast-forward merge.
1106+ iter := object .NewCommitPreorderIter (c , nil , parentsToIgnore )
10931107 err = iter .ForEach (func (c * object.Commit ) error {
10941108 if c .Hash != old {
10951109 return nil
@@ -1205,7 +1219,7 @@ func (r *Remote) updateLocalReferenceStorage(
12051219 // If the ref exists locally as a non-tag and force is not
12061220 // specified, only update if the new ref is an ancestor of the old
12071221 if old != nil && ! old .Name ().IsTag () && ! force && ! spec .IsForceUpdate () {
1208- ff , err := isFastForward (r .s , old .Hash (), new .Hash ())
1222+ ff , err := isFastForward (r .s , old .Hash (), new .Hash (), nil )
12091223 if err != nil {
12101224 return updated , err
12111225 }
@@ -1390,7 +1404,6 @@ func pushHashes(
13901404 useRefDeltas bool ,
13911405 allDelete bool ,
13921406) (* packp.ReportStatus , error ) {
1393-
13941407 rd , wr := io .Pipe ()
13951408
13961409 config , err := s .Config ()
0 commit comments