mirror of
https://github.com/git-learning-game/oh-my-git.git
synced 2024-11-24 16:20:08 +01:00
Show deleted files in the working directory and the index
This commit is contained in:
parent
20358f78a1
commit
107d6f8fb1
3 changed files with 29 additions and 13 deletions
|
@ -34,21 +34,28 @@ func clear():
|
||||||
for item in grid.get_children():
|
for item in grid.get_children():
|
||||||
item.queue_free()
|
item.queue_free()
|
||||||
|
|
||||||
|
func substr2(s):
|
||||||
|
return s.substr(2)
|
||||||
|
|
||||||
func update():
|
func update():
|
||||||
if grid:
|
if grid:
|
||||||
clear()
|
clear()
|
||||||
match mode:
|
match mode:
|
||||||
FileBrowserMode.WORKING_DIRECTORY:
|
FileBrowserMode.WORKING_DIRECTORY:
|
||||||
if shell:
|
if shell:
|
||||||
var file_string = shell.run("find . -type f")
|
var wd_files = Array(shell.run("find . -type f").split("\n"))
|
||||||
var files = file_string.split("\n")
|
|
||||||
files = Array(files)
|
|
||||||
# The last entry is an empty string, remove it.
|
# The last entry is an empty string, remove it.
|
||||||
files.pop_back()
|
wd_files.pop_back()
|
||||||
|
wd_files = helpers.map(wd_files, self, "substr2")
|
||||||
|
|
||||||
|
var deleted_files = Array(shell.run("git status -s | grep '^.D' | sed -r 's/^...//'").split("\n"))
|
||||||
|
deleted_files.pop_back()
|
||||||
|
|
||||||
|
var files = wd_files + deleted_files
|
||||||
|
|
||||||
files.sort_custom(self, "very_best_sort")
|
files.sort_custom(self, "very_best_sort")
|
||||||
var is_visible = false
|
var is_visible = false
|
||||||
for file_path in files:
|
for file_path in files:
|
||||||
file_path = file_path.substr(2)
|
|
||||||
if file_path.substr(0, 5) == ".git/":
|
if file_path.substr(0, 5) == ".git/":
|
||||||
continue
|
continue
|
||||||
is_visible = true
|
is_visible = true
|
||||||
|
@ -74,9 +81,12 @@ func update():
|
||||||
FileBrowserMode.INDEX:
|
FileBrowserMode.INDEX:
|
||||||
var is_visible = false
|
var is_visible = false
|
||||||
if repository and repository.there_is_a_git():
|
if repository and repository.there_is_a_git():
|
||||||
var files = Array(repository.shell.run("git ls-files -s | cut -f2 | uniq").split("\n"))
|
var index_files = Array(repository.shell.run("git ls-files -s | cut -f2 | uniq").split("\n"))
|
||||||
# The last entry is an empty string, remove it.
|
var deleted_files = Array(repository.shell.run("git status -s | grep '^D' | sed -r 's/^...//'").split("\n"))
|
||||||
files.pop_back()
|
# The last entries are empty strings, remove them.
|
||||||
|
index_files.pop_back()
|
||||||
|
deleted_files.pop_back()
|
||||||
|
var files = index_files + deleted_files
|
||||||
for file_path in files:
|
for file_path in files:
|
||||||
var item = preload("res://scenes/file_browser_item.tscn").instance()
|
var item = preload("res://scenes/file_browser_item.tscn").instance()
|
||||||
item.label = file_path
|
item.label = file_path
|
||||||
|
@ -107,6 +117,9 @@ func get_file_status(file_path, shell, idx):
|
||||||
return FileBrowserItem.IconStatus.NONE
|
return FileBrowserItem.IconStatus.NONE
|
||||||
|
|
||||||
func item_clicked(item):
|
func item_clicked(item):
|
||||||
|
if item.status == item.IconStatus.REMOVED:
|
||||||
|
return
|
||||||
|
|
||||||
match mode:
|
match mode:
|
||||||
FileBrowserMode.WORKING_DIRECTORY:
|
FileBrowserMode.WORKING_DIRECTORY:
|
||||||
text_edit.text = helpers.read_file(shell._cwd + item.label)
|
text_edit.text = helpers.read_file(shell._cwd + item.label)
|
||||||
|
@ -159,10 +172,8 @@ func _set_title(new_title):
|
||||||
title_label.text = new_title
|
title_label.text = new_title
|
||||||
|
|
||||||
func very_best_sort(a,b):
|
func very_best_sort(a,b):
|
||||||
# We're looking at the third character because all entries have the form
|
if a[0] == "." and b[0] != ".":
|
||||||
# "./.git/bla".
|
|
||||||
if a.substr(2, 1) == "." and b.substr(2, 1) != ".":
|
|
||||||
return false
|
return false
|
||||||
if a.substr(2, 1) != "." and b.substr(2, 1) == ".":
|
if a[0] != "." and b[0] == ".":
|
||||||
return true
|
return true
|
||||||
return a.casecmp_to(b) == -1
|
return a.casecmp_to(b) == -1
|
||||||
|
|
|
@ -27,7 +27,6 @@ __meta__ = {
|
||||||
}
|
}
|
||||||
|
|
||||||
[node name="DropArea" parent="Control" instance=ExtResource( 4 )]
|
[node name="DropArea" parent="Control" instance=ExtResource( 4 )]
|
||||||
show_behind_parent = false
|
|
||||||
position = Vector2( 0, 0 )
|
position = Vector2( 0, 0 )
|
||||||
|
|
||||||
[node name="VBoxContainer" type="VBoxContainer" parent="."]
|
[node name="VBoxContainer" type="VBoxContainer" parent="."]
|
||||||
|
|
|
@ -11,6 +11,12 @@ func crash(message):
|
||||||
# Violent delights have violent ends.
|
# Violent delights have violent ends.
|
||||||
get_tree().fatal_error()
|
get_tree().fatal_error()
|
||||||
|
|
||||||
|
func map(array, object, f):
|
||||||
|
var new_array = []
|
||||||
|
for i in range(array.size()):
|
||||||
|
new_array.push_back(object.call(f, array[i]))
|
||||||
|
return new_array
|
||||||
|
|
||||||
# Run a simple command with arguments, blocking, using OS.execute.
|
# Run a simple command with arguments, blocking, using OS.execute.
|
||||||
func exec(command, args=[], crash_on_fail=true):
|
func exec(command, args=[], crash_on_fail=true):
|
||||||
var debug = false
|
var debug = false
|
||||||
|
|
Loading…
Reference in a new issue