Skip to content

Commit

Permalink
Merge pull request #461 from groldan/bug/pull_nothing_to_fetch
Browse files Browse the repository at this point in the history
Bug/pull nothing to fetch
  • Loading branch information
groldan authored Sep 11, 2018
2 parents d34a2b2 + 9c3b665 commit 2b615b0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import static com.google.common.base.Preconditions.checkNotNull;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.eclipse.jdt.annotation.Nullable;
Expand Down Expand Up @@ -131,7 +130,8 @@ public boolean isFullDepth() {
}

/**
* @param refSpec the refspec of a remote branch
* @param refSpec specifies a remote ref to fetch and optionally which local ref to update,
* using the format {@code <remote ref>[:<localRef>]}
* @return {@code this}
*/
public PullOp addRefSpec(final String refSpec) {
Expand Down Expand Up @@ -233,16 +233,6 @@ protected PullResult _call() {
result.setOldRef(currentBranch);
result.setRemote(suppliedRemote);

// did fetch need to update any contents?
{
final Collection<RefDiff> fetchedRefs = fetchResult.getRefDiffs()
.get(remote.getFetchURL());
if (fetchedRefs == null || fetchedRefs.isEmpty()) {
result.setNewRef(currentBranch);
return result;
}
}

for (LocalRemoteRefSpec fetchspec : remote.getFetchSpecs()) {
final String localRemoteRefName = fetchspec.getLocal();
final Optional<Ref> localRemoteRefOpt = command(RefParse.class)
Expand Down Expand Up @@ -286,14 +276,4 @@ private Ref resolveCurrentBranch() {
return command(BranchResolveOp.class).call().orElseThrow(
() -> new IllegalStateException("Repository has no HEAD, can't pull."));
}

/**
* @param ref the ref to find
* @return an {@link Optional} of the ref, or {@link Optional#absent()} if it wasn't found
*/
public Optional<Ref> findRemoteRef(String ref) {

String remoteRef = Ref.REMOTES_PREFIX + remote.get().get().getName() + "/" + ref;
return command(RefParse.class).setName(remoteRef).call();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,25 @@ public void testPullMerge() throws Exception {
assertEquals(expectedMaster, logged);
}

@Test
public void testPullMergeNothingToFetch() throws Exception {
// Add a commit to the remote
insertAndAdd(remoteGeogig.geogig, lines3);
RevCommit commit = commit(remoteGeogig.repo, "lines3");
expectedMaster.addFirst(commit);

// call fetch first so the missing objects are already in the local repo
fetchOp().call();

// Then Pull should update the target ref even if there's nothing to fetch
PullOp pull = pullOp();
pull.setRemote("origin").call();

List<RevCommit> logged = log(localGeogig.repo);

assertEquals(expectedMaster, logged);
}

/**
* Pull from a remote that's not being saved as named remote in the repository
*/
Expand Down

0 comments on commit 2b615b0

Please sign in to comment.