mirror of
https://gitlab.gnome.org/GNOME/gitg
synced 2024-09-29 20:53:40 +00:00
Deal correctly with stage/unstage of selection on new files
This commit is contained in:
parent
6785cd73f8
commit
efe545bc75
|
@ -1275,6 +1275,8 @@ namespace GitgCommit
|
|||
|
||||
foreach (var pset in selection)
|
||||
{
|
||||
if (pset.patches.length == 0)
|
||||
continue;
|
||||
if (staging)
|
||||
{
|
||||
yield stage.stage_patch(pset);
|
||||
|
@ -1284,6 +1286,7 @@ namespace GitgCommit
|
|||
yield stage.unstage_patch(pset);
|
||||
}
|
||||
}
|
||||
d_main.diff_view.clear_selection();
|
||||
}
|
||||
|
||||
private async void discard_selection() throws Error
|
||||
|
|
|
@ -23,6 +23,7 @@ interface Gitg.DiffSelectable : Object
|
|||
public abstract bool can_select { get; construct set; }
|
||||
|
||||
public abstract PatchSet selection { owned get; }
|
||||
public abstract void clear_selection ();
|
||||
}
|
||||
|
||||
// ex:ts=4 noet
|
||||
|
|
|
@ -128,6 +128,10 @@ class Gitg.DiffViewFileRendererTextSplit : Gtk.Box, DiffSelectable, DiffViewFile
|
|||
}
|
||||
}
|
||||
|
||||
public void clear_selection()
|
||||
{
|
||||
}
|
||||
|
||||
public bool can_select { get; construct set; }
|
||||
|
||||
public PatchSet selection
|
||||
|
|
|
@ -68,6 +68,8 @@ class Gitg.DiffViewFileRendererText : Gtk.SourceView, DiffSelectable, DiffViewFi
|
|||
private Settings? d_stylesettings;
|
||||
|
||||
private FontManager d_font_manager;
|
||||
private bool d_has_selection;
|
||||
|
||||
public Style d_style { get; construct set; }
|
||||
|
||||
public bool new_is_workdir { get; construct set; }
|
||||
|
@ -122,7 +124,10 @@ class Gitg.DiffViewFileRendererText : Gtk.SourceView, DiffSelectable, DiffViewFi
|
|||
}
|
||||
}
|
||||
|
||||
private bool d_has_selection;
|
||||
public void clear_selection()
|
||||
{
|
||||
d_has_selection = false;
|
||||
}
|
||||
|
||||
public bool has_selection
|
||||
{
|
||||
|
|
|
@ -96,6 +96,15 @@ class Gitg.DiffViewFile : Gtk.Grid
|
|||
return has_selection;
|
||||
}
|
||||
|
||||
public void clear_selection()
|
||||
{
|
||||
foreach (var renderer in renderer_list)
|
||||
{
|
||||
var sel = renderer as DiffSelectable;
|
||||
sel.clear_selection();
|
||||
}
|
||||
}
|
||||
|
||||
public PatchSet get_selection()
|
||||
{
|
||||
var ret = new PatchSet();
|
||||
|
|
|
@ -853,6 +853,7 @@ public class Gitg.DiffView : Gtk.Grid
|
|||
renderer_text.notify["has-selection"].connect(on_selection_changed);
|
||||
}
|
||||
}
|
||||
on_selection_changed();
|
||||
}
|
||||
if (current_is_binary)
|
||||
{
|
||||
|
@ -1061,6 +1062,14 @@ public class Gitg.DiffView : Gtk.Grid
|
|||
return ret;
|
||||
}
|
||||
|
||||
public void clear_selection()
|
||||
{
|
||||
foreach (var file in d_grid_files.get_children())
|
||||
{
|
||||
((Gitg.DiffViewFile)file).clear_selection();
|
||||
}
|
||||
}
|
||||
|
||||
private void update_hide_show_options(Gdk.Window window, int ex, int ey)
|
||||
{
|
||||
void *data;
|
||||
|
|
|
@ -874,15 +874,17 @@ public class Stage : Object
|
|||
yield thread_index((index) => {
|
||||
var entries = index.get_entries();
|
||||
var entry = entries.get_by_path(newf, 0);
|
||||
|
||||
uchar[] old_content = new uchar[0];
|
||||
if (entry == null)
|
||||
{
|
||||
throw new StageError.INDEX_ENTRY_NOT_FOUND(patch.filename);
|
||||
print("\npath not in index %s\n", newf.get_path());
|
||||
index.add_file(newf);
|
||||
index.write();
|
||||
} else {
|
||||
var old_blob = d_repository.lookup<Ggit.Blob>(entry.get_id());
|
||||
old_content = old_blob.get_raw_content();
|
||||
}
|
||||
|
||||
var old_blob = d_repository.lookup<Ggit.Blob>(entry.get_id());
|
||||
unowned uchar[] old_content = old_blob.get_raw_content();
|
||||
|
||||
var old_stream = new MemoryInputStream.from_bytes(new Bytes(old_content));
|
||||
|
||||
apply_patch(index, old_stream, new_stream, patch);
|
||||
|
@ -957,14 +959,22 @@ public class Stage : Object
|
|||
|
||||
if (entry == null)
|
||||
{
|
||||
throw new StageError.INDEX_ENTRY_NOT_FOUND(patch.filename);
|
||||
index.add_file(file);
|
||||
index.write();
|
||||
entries = index.get_entries();
|
||||
entry = entries.get_by_path(file, 0);
|
||||
}
|
||||
|
||||
var head_entry = tree.get_by_path(patch.filename);
|
||||
var head_blob = d_repository.lookup<Ggit.Blob>(head_entry.get_id());
|
||||
var index_blob = d_repository.lookup<Ggit.Blob>(entry.get_id());
|
||||
|
||||
unowned uchar[] head_content = head_blob.get_raw_content();
|
||||
uchar[] head_content = new uchar[0];
|
||||
try {
|
||||
var head_entry = tree.get_by_path(patch.filename);
|
||||
var head_blob = d_repository.lookup<Ggit.Blob>(head_entry.get_id());
|
||||
|
||||
head_content = head_blob.get_raw_content();
|
||||
} catch (Error e) {}
|
||||
|
||||
var index_blob = d_repository.lookup<Ggit.Blob>(entry.get_id());
|
||||
unowned uchar[] index_content = index_blob.get_raw_content();
|
||||
|
||||
var head_stream = new MemoryInputStream.from_bytes(new Bytes(head_content));
|
||||
|
@ -972,7 +982,21 @@ public class Stage : Object
|
|||
|
||||
var reversed = patch.reversed();
|
||||
|
||||
apply_patch(index, index_stream, head_stream, reversed);
|
||||
try {
|
||||
apply_patch(index, index_stream, head_stream, reversed);
|
||||
} catch(Error e) {
|
||||
var stage = d_repository.stage;
|
||||
stage.delete_path.begin(file.get_path(), (obj, res) => {
|
||||
try
|
||||
{
|
||||
stage.delete_path.end(res);
|
||||
}
|
||||
catch (Error e)
|
||||
{
|
||||
warning("%s\n", e.message);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
head_stream.close();
|
||||
index_stream.close();
|
||||
|
|
Loading…
Reference in a new issue