Skip to content

Commit 57e44bc

Browse files
committed
logging the cloning progress to console, so far.
1 parent 7947131 commit 57e44bc

File tree

1 file changed

+44
-35
lines changed

1 file changed

+44
-35
lines changed

mobile/src/main/java/io/syslogic/github/fragment/RepositoryFragment.java

Lines changed: 44 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import java.io.IOException;
3030

3131
import java.util.ArrayList;
32-
import java.util.Collection;
3332

3433
import androidx.annotation.NonNull;
3534
import androidx.annotation.Nullable;
@@ -41,7 +40,7 @@
4140
import org.eclipse.jgit.api.Git;
4241
import org.eclipse.jgit.api.errors.GitAPIException;
4342
import org.eclipse.jgit.api.errors.JGitInternalException;
44-
import org.eclipse.jgit.lib.AnyObjectId;
43+
import org.eclipse.jgit.lib.ProgressMonitor;
4544
import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider;
4645

4746
import io.syslogic.github.R;
@@ -65,7 +64,7 @@
6564
*
6665
* @author Martin Zeitler
6766
*/
68-
public class RepositoryFragment extends BaseFragment implements TokenCallback, CloneCommand.Callback {
67+
public class RepositoryFragment extends BaseFragment implements TokenCallback, ProgressMonitor {
6968

7069
/** Log Tag */
7170
@SuppressWarnings("unused")
@@ -180,47 +179,44 @@ public void onNothingSelected(AdapterView<?> parent) {}
180179
}
181180
}
182181
if (destination.exists()) {
183-
gitClone(destination);
182+
String branch = getDataBinding().toolbarDownload.spinnerBranch.getSelectedItem().toString();
183+
gitClone(destination, branch);
184184
}
185185
});
186186
}
187187
}
188188
return this.mDataBinding.getRoot();
189189
}
190190

191-
/** TODO: git clone (experimental). */
192-
private void gitClone(@NonNull File destination) {
191+
/** git clone. */
192+
private void gitClone(@NonNull File destination, @Nullable String branch) {
193193
Thread thread = new Thread(() -> {
194194
CloneCommand cmd = Git.cloneRepository()
195195
.setURI(getRepoUrl())
196-
.setDirectory(destination)
197-
.setRemote("github")
198-
.setCloneAllBranches(true)
199196
.setCredentialsProvider(new UsernamePasswordCredentialsProvider(getPersonalAccessToken(), ""))
200-
.setCallback(RepositoryFragment.this);
201-
/*
202-
.setTransportConfigCallback(transport -> {
203-
Map<String, String> headers = new HashMap<>();
204-
headers.put("Authorization", getPersonalAccessToken());
205-
TransportHttp http = (TransportHttp) transport;
206-
http.setAdditionalHeaders(headers);
207-
});
208-
*/
209-
try {
210-
if (mDebug) {Log.d(LOG_TAG, "cloning into " + getRepoName());}
211-
Git result = cmd.call();
212-
org.eclipse.jgit.lib.Repository repo = result.getRepository();
213-
repo.close();
197+
.setProgressMonitor(RepositoryFragment.this)
198+
.setDirectory(destination)
199+
.setRemote("github");
214200

201+
if (branch == null) {
202+
cmd.setCloneAllBranches(true);
203+
} else {
204+
cmd.setBranch(branch);
205+
}
206+
207+
try {
208+
if (mDebug) {Log.d(LOG_TAG, "Cloning into " + getRepoName() + "...");}
209+
cmd.call();
215210
} catch (GitAPIException | JGitInternalException | NoSuchMethodError e) {
216211
String message = e.getMessage();
217212
if (mDebug) {Log.e(LOG_TAG, e.getMessage(), e);}
218213
requireActivity().runOnUiThread(() ->
219214
Toast.makeText(requireContext(), message, Toast.LENGTH_LONG).show());
220215
} finally {
221-
if (mDebug) {
222-
Log.d(LOG_TAG, "cloning complete");
223-
}
216+
String message = "Cloned.";
217+
if (mDebug) {Log.d(LOG_TAG, message);}
218+
requireActivity().runOnUiThread(() ->
219+
Toast.makeText(requireContext(), message, Toast.LENGTH_LONG).show());
224220
}
225221
});
226222
thread.start();
@@ -555,21 +551,34 @@ private void switchToolbarView(@NonNull Integer childIndex) {
555551
@Override
556552
public void onLogin(@NonNull User item) {}
557553

558-
/** Interface: CloneCommand.Callback */
554+
/** Interface: ProgressMonitor */
555+
@Override
556+
public void start(int totalTasks) {
557+
if (mDebug) {Log.d(LOG_TAG, "totalTasks: " + totalTasks);}
558+
}
559+
560+
/** Interface: ProgressMonitor */
561+
@Override
562+
public void beginTask(String title, int totalWork) {
563+
if (mDebug) {Log.d(LOG_TAG, "beginTask " + title + ": " + totalWork);}
564+
}
565+
566+
/** Interface: ProgressMonitor */
559567
@Override
560-
public void initializedSubmodules(Collection<String> submodules) {
561-
if (mDebug) {Log.d(LOG_TAG, "initializedSubmodules");}
568+
public void update(int completed) {
569+
if (mDebug) {Log.d(LOG_TAG, "completed: +" + completed);}
562570
}
563571

564-
/** Interface: CloneCommand.Callback */
572+
/** Interface: ProgressMonitor */
565573
@Override
566-
public void cloningSubmodule(String path) {
567-
if (mDebug) {Log.d(LOG_TAG, "cloningSubmodule");}
574+
public void endTask() {
575+
if (mDebug) {Log.d(LOG_TAG, "endTask");}
568576
}
569577

570-
/** Interface: CloneCommand.Callback */
578+
/** Interface: ProgressMonitor */
571579
@Override
572-
public void checkingOut(AnyObjectId commit, String path) {
573-
if (mDebug) {Log.d(LOG_TAG, "checkingOut");}
580+
public boolean isCancelled() {
581+
// if (mDebug) {Log.d(LOG_TAG, "isCancelled?");}
582+
return false;
574583
}
575584
}

0 commit comments

Comments
 (0)