Skip to content

Commit 1028ae4

Browse files
committed
update refs is complicated
1 parent f55a29f commit 1028ae4

2 files changed

Lines changed: 17 additions & 3 deletions

File tree

git-incrypt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,6 @@ class CryptRepo:
155155
poutput = ctypes.c_char_p(ctypes.addressof(output))
156156
plugin.writemeta(poutput)
157157
self.repo = pygit2.Repository('.')
158-
blubs = self.repo.get(output.value.decode('utf-8')).id
159-
self.repo.create_reference(
160-
plugin.getprefix().decode('utf-8') + '1/_', blubs, force=True)
161158
self.meta = MetaData(self.repo)
162159
self.trust(force=True, sign=True)
163160
else:

incrypt-plugin.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
#include "strbuf.h"
2121
#include "sigchain.h"
2222
#include "gettext.h"
23+
//#include "config.h"
24+
//#include "environment.h"
2325

2426
void globalinit(const char* dir, const char* url_arg);
2527
int set_option(const char *name, size_t namelen, const char *value);
@@ -48,6 +50,7 @@ void metainit(void);
4850
char* writemeta(char* output);
4951
int encrypt_buffer_gpg(struct strbuf *buffer, struct strbuf *output,
5052
struct string_list *recipients);
53+
void myupdaterefs(const char* refname, const char* oid);
5154

5255
/*static*/ const char* CRYPTREADME = "# 401 Unauthorized\n\n"
5356
"This is an encrypted git repository. You can clone it, but you will not be\n"
@@ -385,6 +388,14 @@ void fetchpattern(const char pattern) {
385388
/*return*/ run_command(&cmd);
386389
}
387390

391+
void myupdaterefs(const char* refname, const char* oid) {
392+
struct child_process cmd = CHILD_PROCESS_INIT;
393+
strvec_pushl(&cmd.args, "update-ref", refname, oid, NULL);
394+
cmd.git_cmd = 1;
395+
//This causes a crash! : cmd.close_object_store = 1;
396+
/*return*/ run_command(&cmd);
397+
}
398+
388399
const char* ver = "git-incrypt\n1.0.0\n";
389400
const char* keyver = "AES-256-CBC+IV";
390401
struct object_id obj_ver;
@@ -452,6 +463,7 @@ char* writemeta(char* output) {
452463
size_t mapencryptedlen = 0;
453464
struct object_id obj_readme;
454465
struct object_id obj_map;
466+
struct strbuf refname = STRBUF_INIT;
455467
odb_write_object(the_repository->objects, CRYPTREADME, strlen(CRYPTREADME), OBJ_BLOB, &obj_readme);
456468
strbuf_addf(&tb, "%o %s%c", 0100644, "README.md", '\0');
457469
strbuf_add(&tb, obj_readme.hash, the_hash_algo->rawsz);
@@ -477,6 +489,11 @@ char* writemeta(char* output) {
477489
odb_write_object(the_repository->objects, tb.buf, tb.len, OBJ_TREE, &tid);
478490
strbuf_release(&tb);
479491
secretcommit(&tid, &oid);
492+
strbuf_addf(&refname, "%s1/_", prefix);
493+
// refs_update_ref(get_main_ref_store(the_repository), NULL, refname.buf,
494+
// &oid, NULL, 0, UPDATE_REFS_MSG_ON_ERR);
495+
myupdaterefs(refname.buf, oid_to_hex(&oid));
496+
strbuf_release(&refname);
480497
memcpy(output, oid_to_hex(&oid), 41);
481498
return output;
482499
}

0 commit comments

Comments
 (0)