Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions app/src/main/java/com/orgzly/android/git/GitFileSynchronizer.java
Original file line number Diff line number Diff line change
Expand Up @@ -288,13 +288,26 @@ public void setBranchAndGetLatest() throws IOException {
throw new IOException(String.format("Failed to merge %s and %s",
current.getName(), mergeTarget.getName()));
}
} else {
// We failed to find a corresponding remote head. Check if the repo is completely
// empty, and if so, push to it.
pushToRemoteIfEmpty();
}
} catch (GitAPIException e) {
e.printStackTrace();
throw new IOException("Failed to update from remote");
}
}

private void pushToRemoteIfEmpty() throws GitAPIException {
List<Ref> remoteBranches = git.branchList()
.setListMode(ListBranchCommand.ListMode.REMOTE)
.call();
if (remoteBranches.isEmpty()) {
tryPush();
}
}

public boolean attemptReturnToMainBranch() throws IOException {
ensureRepoIsClean();
String originalBranch = git.getRepository().getBranch();
Expand Down Expand Up @@ -375,6 +388,9 @@ public RevCommit getCommit(String identifier) throws IOException {
return null;
}
Ref target = git.getRepository().findRef(identifier);
if (target == null) {
return null;
}
return new RevWalk(git.getRepository()).parseCommit(target.getObjectId());
}

Expand Down