Skip to content
Draft
Show file tree
Hide file tree
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
7 changes: 7 additions & 0 deletions src/Dialogs/CloneRepositoryDialog.vala
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class Scratch.Dialogs.CloneRepositoryDialog : Granite.MessageDialog {
private Gtk.Spinner spinner;

public bool can_clone { get; private set; default = false; }
public bool update_submodules { get; set; default = true; }
public string suggested_local_folder { get; construct; }
public string suggested_remote { get; construct; }

Expand Down Expand Up @@ -114,10 +115,16 @@ public class Scratch.Dialogs.CloneRepositoryDialog : Granite.MessageDialog {
};
local_project_name_entry.changed.connect (validate_local_name);

var update_submodules_checkbox = new Gtk.CheckButton.with_label (_("Update submodules")) {
margin_top = 12,
halign = START
};
this.bind_property ("update-submodules", update_submodules_checkbox, "active", BIDIRECTIONAL | SYNC_CREATE );
var content_box = new Gtk.Box (VERTICAL, 0);
content_box.add (new CloneEntry (_("Repository URL"), remote_repository_uri_entry));
content_box.add (new CloneEntry (_("Location"), folder_chooser_button));
content_box.add (new CloneEntry (_("Name of Clone"), local_project_name_entry));
content_box.add (update_submodules_checkbox);

var cloning_label = new Granite.HeaderLabel (_("Cloning in progress"));
spinner = new Gtk.Spinner ();
Expand Down
15 changes: 14 additions & 1 deletion src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -1064,21 +1064,34 @@ namespace Scratch {
git_manager.clone_repository.begin (
uri,
target,
clone_dialog.update_submodules,
(obj, res) => {
clone_dialog.cloning_in_progress = false;
File? workdir = null;
string? error = null;
if (git_manager.clone_repository.end (res, out workdir, out error)) {
open_folder (workdir);
clone_dialog.destroy ();
var primary_text = "";
if (error == null) {
primary_text = _("Repository %s successfully cloned").printf (uri);
} else {
// e.g. Problem updating submodules
primary_text = _("Repository %s cloned with error").printf (uri);
}
var message_dialog = new Granite.MessageDialog.with_image_from_icon_name (
_("Repository %s successfully cloned").printf (uri),
primary_text,
_("Local repository working directory is %s").printf (workdir.get_uri ()),
"dialog-information",
Gtk.ButtonsType.CLOSE
) {
transient_for = this
};

if (error != null) {
message_dialog.show_error_details (error);
}

message_dialog.response.connect (message_dialog.destroy);
message_dialog.present ();
} else {
Expand Down
13 changes: 11 additions & 2 deletions src/Services/GitManager.vala
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ namespace Scratch.Services {
public async bool clone_repository (
string uri,
string local_folder,
bool update_submodules,
out File? repo_workdir,
out string? error
) {
Expand Down Expand Up @@ -144,9 +145,15 @@ namespace Scratch.Services {
folder_file,
clone_options
);

if (update_submodules) {
new_repo.submodule_foreach ((submodule, name) => {
submodule.update (true, null);
return 0;
});
}
} catch (Error e) {
e_message = e.message;
new_repo = null;
}

Idle.add ((owned)callback);
Expand All @@ -155,7 +162,9 @@ namespace Scratch.Services {
yield;
if (new_repo != null) {
repo_workdir = new_repo.get_workdir ();
} else {
}

if (e_message != "") {
error = e_message;
}

Expand Down