mirror of
https://github.com/git-learning-game/oh-my-git.git
synced 2024-11-11 19:04:50 +01:00
Basic Git object functionality
This commit is contained in:
parent
2ceb1eeb89
commit
1d6fdb9b8a
2 changed files with 75 additions and 1 deletions
72
main.gd
Normal file
72
main.gd
Normal file
|
@ -0,0 +1,72 @@
|
|||
extends Node2D
|
||||
|
||||
func _ready():
|
||||
for o in all_objects():
|
||||
print(" ")
|
||||
print(o)
|
||||
var type = object_type(o)
|
||||
print(type)
|
||||
#print(object_content(o))
|
||||
match type:
|
||||
"blob":
|
||||
pass
|
||||
"tree":
|
||||
print("Children:")
|
||||
print(tree_children(o))
|
||||
"commit":
|
||||
print("Tree:")
|
||||
print(commit_tree(o))
|
||||
|
||||
print("Parents:")
|
||||
print(commit_parents(o))
|
||||
|
||||
func git(args, splitlines = false):
|
||||
var output = []
|
||||
var a = args.split(" ")
|
||||
a.insert(0, "-C")
|
||||
a.insert(1, "/home/seb/tmp/godotgit")
|
||||
#print ("Running: ", a)
|
||||
OS.execute("git", a, true, output, true)
|
||||
var o = output[0]
|
||||
if splitlines:
|
||||
o = o.split("\n")
|
||||
o.remove(len(o)-1)
|
||||
else:
|
||||
o = o.substr(0,len(o)-1)
|
||||
return o
|
||||
|
||||
func all_objects():
|
||||
return git("cat-file --batch-check=%(objectname) --batch-all-objects", true)
|
||||
|
||||
func object_type(id):
|
||||
return git("cat-file -t "+id)
|
||||
|
||||
func object_content(id):
|
||||
return git("cat-file -p "+id)
|
||||
|
||||
func tree_children(id):
|
||||
var children = git("cat-file -p "+id, true)
|
||||
var ids = []
|
||||
for c in children:
|
||||
var a = c.split(" ")
|
||||
ids.push_back(a[2].split("\t")[0])
|
||||
return ids
|
||||
|
||||
func commit_tree(id):
|
||||
var c = git("cat-file -p "+id, true)
|
||||
for cc in c:
|
||||
var ccc = cc.split(" ", 2)
|
||||
match ccc[0]:
|
||||
"tree":
|
||||
return ccc[1]
|
||||
return null
|
||||
|
||||
func commit_parents(id):
|
||||
var parents = []
|
||||
var c = git("cat-file -p "+id, true)
|
||||
for cc in c:
|
||||
var ccc = cc.split(" ", 2)
|
||||
match ccc[0]:
|
||||
"parent":
|
||||
parents.push_back(ccc[1])
|
||||
return parents
|
|
@ -1,8 +1,10 @@
|
|||
[gd_scene load_steps=2 format=2]
|
||||
[gd_scene load_steps=3 format=2]
|
||||
|
||||
[ext_resource path="res://player.tscn" type="PackedScene" id=1]
|
||||
[ext_resource path="res://main.gd" type="Script" id=2]
|
||||
|
||||
[node name="Main" type="Node2D"]
|
||||
script = ExtResource( 2 )
|
||||
|
||||
[node name="Player" parent="." instance=ExtResource( 1 )]
|
||||
position = Vector2( 960, 540 )
|
||||
|
|
Loading…
Reference in a new issue