Guest User

Untitled

a guest
Aug 9th, 2018
469
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 24.17 KB | None | 0 0
  1. #!./Files/bash-4.4.0
  2. git config --global user.email "null@gmail.com"
  3. git config --global user.name "null"
  4. git add --all
  5. git commit -m -a
  6. git push --force origin master
  7.  
  8. git filter-branch --index-filter 'git rm --cached --ignore-unmatch $1' -- --all
  9.  
  10. push> touch k
  11. push> ggitnadd k
  12. ggitnadd : Command not found.
  13. push> git add k
  14. git_libgit2_features() = 15
  15. git_libgit2_init() = 1
  16. called
  17. add 'k'
  18. push> git commit k
  19. git_libgit2_init() = 1
  20. git_repository_head_unborn(repo) = 0
  21. aquiring reference
  22. git_reference_name_to_id(&parent_id,repo,"HEAD") = 0 (none)
  23. looking up reference
  24. git_commit_lookup(&parent,repo,&parent_id) = 0 (none)
  25. attemting to commit
  26. git_commit_tree(&tree,parent) = 0 (none)
  27. ret = 0 (none)
  28. commit sucessfull
  29. push> git status
  30. # On branch
  31. # Changes to be committed:
  32. # (use "git reset HEAD <file>..." to unstage)
  33. #
  34. # new file: gfd
  35. # new file: k
  36. # new file: te
  37. #
  38. push> git commit -a
  39. git_libgit2_init() = 1
  40. git_repository_head_unborn(repo) = 0
  41. aquiring reference
  42. git_reference_name_to_id(&parent_id,repo,"HEAD") = 0 (none)
  43. looking up reference
  44. git_commit_lookup(&parent,repo,&parent_id) = 0 (none)
  45. attemting to commit
  46. git_commit_tree(&tree,parent) = 0 (none)
  47. ret = 0 (none)
  48. commit sucessfull
  49. push> git status
  50. # On branch master
  51. # Changes to be committed:
  52. # (use "git reset HEAD <file>..." to unstage)
  53. #
  54. # new file: gfd
  55. # new file: k
  56. # new file: te
  57. #
  58. push>
  59.  
  60. Git> git init
  61. Initialized empty Git repository in ~/CCR/UserFiles/Mobile C/Git/.git
  62. Git> git add -A
  63. git_libgit2_features() = 15
  64. git_libgit2_init() = 1
  65. called
  66. add 'git.c'
  67. called
  68. add 'git/common.c.h'
  69. called
  70. add 'git/common.h'
  71. called
  72. add 'git/git.h'
  73. called
  74. add 'git/git_add.h'
  75. called
  76. add 'git/git_clone.h'
  77. called
  78. add 'git/git_commit.h'
  79. called
  80. add 'git/git_config.h'
  81. called
  82. add 'git/git_curl.h'
  83. called
  84. add 'git/git_hook_config.h'
  85. called
  86. add 'git/git_init.h'
  87. called
  88. add 'git/git_macros.h'
  89. called
  90. add 'git/git_push.h'
  91. called
  92. add 'git/git_remote.h'
  93. called
  94. add 'git/git_stat.h'
  95. called
  96. add 'git/git_tests.h'
  97. called
  98. add 'git/githeader.h'
  99. called
  100. add 'git/strbuf.h'
  101. called
  102. add 'gitcommit'
  103. called
  104. add 'gitremove'
  105. called
  106. add 'tests/push/'
  107. Git> git status
  108. # On branch Not currently on any branch.
  109. # Changes to be committed:
  110. # (use "git reset HEAD <file>..." to unstage)
  111. #
  112. # new file: git.c
  113. # new file: git/common.c.h
  114. # new file: git/common.h
  115. # new file: git/git.h
  116. # new file: git/git_add.h
  117. # new file: git/git_clone.h
  118. # new file: git/git_commit.h
  119. # new file: git/git_config.h
  120. # new file: git/git_curl.h
  121. # new file: git/git_hook_config.h
  122. # new file: git/git_init.h
  123. # new file: git/git_macros.h
  124. # new file: git/git_push.h
  125. # new file: git/git_remote.h
  126. # new file: git/git_stat.h
  127. # new file: git/git_tests.h
  128. # new file: git/githeader.h
  129. # new file: git/strbuf.h
  130. # new file: gitcommit
  131. # new file: gitremove
  132. #
  133. # Untracked files:
  134. # (use "git add <file>..." to include in what will be committed)
  135. #
  136. # tests/push/
  137. Git> git commit -a
  138. git_libgit2_init() = 1
  139. git_repository_head_unborn(repo) = 1
  140. looking up tree
  141. attemting to commit
  142. Git> git status
  143. # On branch master
  144. # Untracked files:
  145. # (use "git add <file>..." to include in what will be committed)
  146. #
  147. # tests/push/
  148. Git>
  149.  
  150. int gitprefix(commit) (int argc, char * argv[]) {
  151. git_repository *repo;
  152. git_signature *sig;
  153. git_index *index;
  154. git_oid tree_id, commit_id;
  155. git_tree *tree;
  156.  
  157. pi(git_libgit2_init());
  158.  
  159. if (git_repository_open(&repo, ".")) {
  160. git_libgit2_shutdown();
  161. giterror("Could not open repository");
  162. }
  163.  
  164. /** First use the config to initialize a commit signature for the user. */
  165.  
  166. if (git_signature_default(&sig, repo) < 0) {
  167. if (git_signature_new(&sig, "null","null@gmail.com",0,0) < 0) {
  168. git_signature_free(sig);
  169. git_repository_free(repo);
  170. git_libgit2_shutdown();
  171. giterror("Unable to create a commit signature.n%s",
  172. "Perhaps 'user.name' and 'user.email' are not set");
  173. }
  174. }
  175.  
  176. /* Now let's create an empty tree for this commit */
  177.  
  178. if (git_repository_index(&index, repo) < 0) {
  179. git_index_free(index);
  180. git_signature_free(sig);
  181. git_repository_free(repo);
  182. git_libgit2_shutdown();
  183. giterror("Could not open repository index", NULL);
  184. }
  185.  
  186. /**
  187. * Outside of this example, you could call git_index_add_bypath()
  188. * here to put actual files into the index. For our purposes, we'll
  189. * leave it empty for now.
  190. */
  191.  
  192. if (git_index_write_tree(&tree_id, index) < 0) {
  193. git_index_free(index);
  194. git_tree_free(tree);
  195. git_signature_free(sig);
  196. git_repository_free(repo);
  197. git_libgit2_shutdown();
  198. giterror("Unable to write initial tree from index", NULL);
  199. }
  200.  
  201. git_index_free(index);
  202.  
  203. pi(git_repository_head_unborn(repo))
  204. if(git_repository_head_unborn(repo) == 1) {
  205. puts("looking up tree");
  206. if (git_tree_lookup(&tree, repo, &tree_id) < 0) {
  207. git_tree_free(tree);
  208. git_signature_free(sig);
  209. git_repository_free(repo);
  210. git_libgit2_shutdown();
  211. giterror("Could not look up initial tree", NULL);
  212. }
  213.  
  214. /**
  215. * Ready to create the initial commit.
  216. *
  217. * Normally creating a commit would involve looking up the current
  218. * HEAD commit and making that be the parent of the initial commit,
  219. * but here this is the first commit so there will be no parent.
  220. */
  221.  
  222. puts("attemting to commit");
  223. int ret = git_commit_create_v(&commit_id, repo, "HEAD", sig, sig, NULL, "Initial commit", tree, 0);
  224. if (ret < 0) {
  225. git_tree_free(tree);
  226. git_signature_free(sig);
  227. git_repository_free(repo);
  228. git_libgit2_shutdown();
  229. giterror("Could not create the initial commit (%d)", ret);
  230. }
  231. } else if (git_repository_head_unborn(repo) == 0) {
  232. git_oid parent_id;
  233. git_commit *parent;
  234. // Get HEAD as a commit object to use as the parent of the commit
  235. puts("aquiring reference");
  236. giterr(git_reference_name_to_id(&parent_id, repo, "HEAD"));
  237. puts("looking up reference");
  238. giterr(git_commit_lookup(&parent, repo, &parent_id));
  239. puts("attemting to commit");
  240. giterr(git_commit_tree(&tree, parent));
  241. int ret = git_commit_create_v(&commit_id, repo, "HEAD", sig, sig, NULL, "-a", tree, 1, parent, NULL);
  242. giterr(ret);
  243. if (ret < 0) {
  244. git_tree_free(tree);
  245. git_repository_free(repo);
  246. git_libgit2_shutdown();
  247. giterror("Could not create the initial commit (%d)", ret);
  248. }
  249. puts("commit sucessfull");
  250.  
  251. }
  252.  
  253. /** Clean up so we don't leak memory. */
  254.  
  255. git_tree_free(tree);
  256. git_signature_free(sig);
  257. git_repository_free(repo);
  258. git_libgit2_shutdown();
  259. return 0;
  260. }
  261.  
  262. int gitprefix(commit2) (int argc, char * argv[]) {
  263. git_repository *repo;
  264. git_signature *sig;
  265. git_index *index;
  266. git_oid tree_id, commit_id;
  267. git_tree *tree = NULL;
  268.  
  269. pi(git_libgit2_init());
  270.  
  271. if (git_repository_open(&repo, ".")) {
  272. git_libgit2_shutdown();
  273. giterror("Could not open repository");
  274. }
  275.  
  276. /** First use the config to initialize a commit signature for the user. */
  277.  
  278. if (git_signature_default(&sig, repo) < 0) {
  279. if (git_signature_new(&sig, "null","null@gmail.com",0,0) < 0) {
  280. git_signature_free(sig);
  281. git_repository_free(repo);
  282. git_libgit2_shutdown();
  283. giterror("Unable to create a commit signature.n%s",
  284. "Perhaps 'user.name' and 'user.email' are not set");
  285. }
  286. }
  287.  
  288. pi(git_repository_head_unborn(repo))
  289. if(git_repository_head_unborn(repo) == 1) {
  290. /* Now let's create an empty tree for this commit */
  291.  
  292. if (git_repository_index(&index, repo) < 0) {
  293. git_index_free(index);
  294. git_signature_free(sig);
  295. git_repository_free(repo);
  296. git_libgit2_shutdown();
  297. giterror("Could not open repository index", NULL);
  298. }
  299.  
  300. /**
  301. * Outside of this example, you could call git_index_add_bypath()
  302. * here to put actual files into the index. For our purposes, we'll
  303. * leave it empty for now.
  304. */
  305.  
  306. if (git_index_write_tree(&tree_id, index) < 0) {
  307. git_index_free(index);
  308. git_tree_free(tree);
  309. git_signature_free(sig);
  310. git_repository_free(repo);
  311. git_libgit2_shutdown();
  312. giterror("Unable to write initial tree from index", NULL);
  313. }
  314.  
  315. git_index_free(index);
  316.  
  317. puts("looking up tree");
  318. if (git_tree_lookup(&tree, repo, &tree_id) < 0) {
  319. git_tree_free(tree);
  320. git_signature_free(sig);
  321. git_repository_free(repo);
  322. git_libgit2_shutdown();
  323. giterror("Could not look up initial tree", NULL);
  324. }
  325.  
  326. /**
  327. * Ready to create the initial commit.
  328. *
  329. * Normally creating a commit would involve looking up the current
  330. * HEAD commit and making that be the parent of the initial commit,
  331. * but here this is the first commit so there will be no parent.
  332. */
  333.  
  334. puts("attemting to commit");
  335. int ret = git_commit_create_v(&commit_id, repo, "HEAD", sig, sig, NULL, "Initial commit", tree, 0);
  336. if (ret < 0) {
  337. git_tree_free(tree);
  338. git_signature_free(sig);
  339. git_repository_free(repo);
  340. git_libgit2_shutdown();
  341. giterror("Could not create the initial commit (%d)", ret);
  342. }
  343. } else if (git_repository_head_unborn(repo) == 0) {
  344. /* Now let's create an empty tree for this commit */
  345.  
  346. if (git_repository_index(&index, repo) < 0) {
  347. git_index_free(index);
  348. git_signature_free(sig);
  349. git_repository_free(repo);
  350. git_libgit2_shutdown();
  351. giterror("Could not open repository index", NULL);
  352. }
  353.  
  354. /**
  355. * Outside of this example, you could call git_index_add_bypath()
  356. * here to put actual files into the index. For our purposes, we'll
  357. * leave it empty for now.
  358. */
  359.  
  360. /* Overwrite the index contents with those of a tree */
  361. giterr(git_revparse_single((git_object**)&tree, repo, "HEAD~^{tree}"));
  362. giterr(git_index_read_tree(index, tree));
  363.  
  364. /* Write the index contents to the ODB as a tree */
  365. giterr(git_index_write_tree(&tree_id, index));
  366.  
  367. /* In-memory indexes can write trees to any repo */
  368. giterr(git_index_write_tree_to(&tree_id, index, repo));
  369.  
  370. git_index_free(index);
  371.  
  372. git_oid parent_id;
  373. git_commit *parent;
  374. git_commit *parent2;
  375. // Get HEAD as a commit object to use as the parent of the commit
  376. puts("aquiring reference");
  377. giterr(git_reference_name_to_id(&parent_id, repo, "HEAD"));
  378. puts("looking up reference");
  379. giterr(git_commit_lookup(&parent, repo, &parent_id));
  380. puts("attemting to commit");
  381. giterr(git_commit_tree(&tree, parent));
  382. int ret = git_commit_create_v(&commit_id, repo, "HEAD", sig, sig, NULL, "-a", tree, 1, parent, NULL);
  383. //int git_commit_parent(git_commit **out, const git_commit *commit, unsigned int n);
  384. //int ret = git_commit_parent(&parent2, parent, 0);
  385. giterr(ret);
  386. if (ret < 0) {
  387. git_tree_free(tree);
  388. git_repository_free(repo);
  389. git_libgit2_shutdown();
  390. giterror("Could not create the commit (%d)", ret);
  391. }
  392. puts("commit sucessfull");
  393.  
  394. }
  395.  
  396. /** Clean up so we don't leak memory. */
  397.  
  398. git_tree_free(tree);
  399. git_signature_free(sig);
  400. git_repository_free(repo);
  401. git_libgit2_shutdown();
  402. return 0;
  403. }
  404.  
  405. int gitprefix(add) (int argc, char** argv)
  406. {
  407. git_index_matched_path_cb matched_cb = &pmatched_cb;
  408. git_repository *repo = NULL;
  409. git_index *index;
  410. git_strarray array = {0};
  411. int options = 0, count = 0;
  412. struct print_payload payload = {0};
  413.  
  414. pi(git_libgit2_features());
  415. pi(git_libgit2_init());
  416.  
  417. gitret(gitprefix(parse_optsA)(&options, &count, argc, argv));
  418.  
  419. gitprefix(init_array)(&array, argc-count, argv+count);
  420.  
  421. if (git_repository_open(&repo, ".")) {
  422. git_repository_free(repo);
  423. git_libgit2_shutdown();
  424. giterror("Could not open repository");
  425. }
  426.  
  427. if (git_repository_index(&index, repo)) {
  428. git_index_free(index);
  429. git_repository_free(repo);
  430. git_libgit2_shutdown();
  431. giterror("Could not open repository index");
  432. }
  433.  
  434. payload.options = options;
  435. payload.repo = repo;
  436.  
  437. git_index_add_all(index, &array, GIT_INDEX_ADD_DEFAULT, matched_cb, &payload);
  438. git_index_update_all(index, &array, matched_cb, &payload);
  439.  
  440. git_index_write(index);
  441. git_index_free(index);
  442. git_repository_free(repo);
  443.  
  444. git_libgit2_shutdown();
  445.  
  446. return 0;
  447. }
  448.  
  449. #define ps(x) printf("%s = %sn", #x, x);
  450. #define pi(x) printf("%s = %dn", #x, x);
  451. #define pp(x) printf("%s = %pn", #x, x);
  452.  
  453. #define gitprefix(x) git_libgit_version_2_api_##x
  454.  
  455.  
  456. #define giterr(x) { printf("%s = %d (%s)n", #x, x, giterr_last()?giterr_last()->message:"none"); }
  457.  
  458. #define giterror(...) {
  459. printf("error: " __VA_ARGS__);
  460. printf(" (%s)", giterr_last()?giterr_last()->message:"none");
  461. printf("n");
  462. return -2;
  463. }
  464.  
  465. #define giterrorn(...) {
  466. printf("error: " __VA_ARGS__);
  467. printf(" (%s)", giterr_last()?giterr_last()->message:"none");
  468. printf("n");
  469. return NULL;
  470. }
  471.  
  472. #define gitret(x) {
  473. int ret = x ;
  474. if (ret) return ret;
  475. }
  476.  
  477. int gitprefix(commit) (int argc, char * argv[]) {
  478. git_repository *repo;
  479. git_signature *sig;
  480. git_index *index;
  481. git_oid tree_id, commit_id;
  482. git_tree *tree;
  483.  
  484. pi(git_libgit2_init());
  485.  
  486. if (git_repository_open(&repo, ".")) {
  487. git_libgit2_shutdown();
  488. giterror("Could not open repository");
  489. }
  490.  
  491. /** First use the config to initialize a commit signature for the user. */
  492.  
  493. if (git_signature_default(&sig, repo) < 0) {
  494. if (git_signature_new(&sig, "null","null@gmail.com",0,0) < 0) {
  495. git_signature_free(sig);
  496. git_repository_free(repo);
  497. git_libgit2_shutdown();
  498. giterror("Unable to create a commit signature.n%s",
  499. "Perhaps 'user.name' and 'user.email' are not set");
  500. }
  501. }
  502.  
  503. /* Now let's create an empty tree for this commit */
  504.  
  505. if (git_repository_index(&index, repo) < 0) {
  506. git_index_free(index);
  507. git_signature_free(sig);
  508. git_repository_free(repo);
  509. git_libgit2_shutdown();
  510. giterror("Could not open repository index", NULL);
  511. }
  512.  
  513. /**
  514. * Outside of this example, you could call git_index_add_bypath()
  515. * here to put actual files into the index. For our purposes, we'll
  516. * leave it empty for now.
  517. */
  518.  
  519. if (git_index_write_tree(&tree_id, index) < 0) {
  520. git_index_free(index);
  521. git_tree_free(tree);
  522. git_signature_free(sig);
  523. git_repository_free(repo);
  524. git_libgit2_shutdown();
  525. giterror("Unable to write initial tree from index", NULL);
  526. }
  527.  
  528. git_index_free(index);
  529.  
  530. pi(git_repository_head_unborn(repo))
  531. if(git_repository_head_unborn(repo) == 1) {
  532. puts("looking up tree");
  533. if (git_tree_lookup(&tree, repo, &tree_id) < 0) {
  534. git_tree_free(tree);
  535. git_signature_free(sig);
  536. git_repository_free(repo);
  537. git_libgit2_shutdown();
  538. giterror("Could not look up initial tree", NULL);
  539. }
  540.  
  541. /**
  542. * Ready to create the initial commit.
  543. *
  544. * Normally creating a commit would involve looking up the current
  545. * HEAD commit and making that be the parent of the initial commit,
  546. * but here this is the first commit so there will be no parent.
  547. */
  548.  
  549. puts("attemting to commit");
  550. int ret = git_commit_create_v(&commit_id, repo, "HEAD", sig, sig, NULL, "Initial commit", tree, 0);
  551. if (ret < 0) {
  552. git_tree_free(tree);
  553. git_signature_free(sig);
  554. git_repository_free(repo);
  555. git_libgit2_shutdown();
  556. giterror("Could not create the initial commit (%d)", ret);
  557. }
  558. } else if (git_repository_head_unborn(repo) == 0) {
  559. git_oid parent_id;
  560. git_commit *parent;
  561. // Get HEAD as a commit object to use as the parent of the commit
  562. puts("aquiring reference");
  563. giterr(git_reference_name_to_id(&parent_id, repo, "HEAD"));
  564. puts("looking up reference");
  565. giterr(git_commit_lookup(&parent, repo, &parent_id));
  566. puts("attemting to commit");
  567. // Do the commit
  568. int ret = git_commit_create_v(&commit_id, repo, "HEAD", sig, sig, NULL, "-a", tree, 1, parent); // seg faults here, does not seg fault if i remove parent but gives -15
  569. if (ret < 0) {
  570. git_tree_free(tree);
  571. git_repository_free(repo);
  572. git_libgit2_shutdown();
  573. giterror("Could not create the initial commit (%d)", ret);
  574. }
  575.  
  576. }
  577.  
  578. /** Clean up so we don't leak memory. */
  579.  
  580. git_tree_free(tree);
  581. git_signature_free(sig);
  582. git_repository_free(repo);
  583. git_libgit2_shutdown();
  584. return 0;
  585. }
  586.  
  587. #include "git/git.h"
  588.  
  589. int _main(void);
  590.  
  591. int rec = 0; // set to 1 to test recursion and stability
  592. int m = 0;
  593. int i = 500;
  594.  
  595. int main(void)
  596. {
  597. str_new(path);
  598. str_new(num);
  599. str_insert_string(path, path.index, "init ");
  600. str_insert_int(num, num.index, m);
  601. str_insert_string(path, path.index, num.string);
  602. str_insert_string(path, path.index, " --initial-commit");
  603. _main(num.string, path.string);
  604. str_free(path)
  605. str_free(num)
  606. if (rec == 1) {
  607. if(m < i) {
  608. m++;
  609. main();
  610. }
  611. if (m <= i) printf("%d <= %dn", m, i);
  612. m--;
  613. }
  614. chdir("../");
  615. return 0;
  616. }
  617.  
  618. int _main(char * dir, char * init)
  619. {
  620. git("init a");
  621. chdir("a");
  622. git("commit");
  623. puts("testing");
  624. git(init);
  625. chdir(dir);
  626. git("commit");
  627. puts("");
  628. puts("");
  629. puts("");
  630. puts("");
  631. touch("test");
  632. mkdir("b",0777);
  633. touch("b/l");
  634. git("add -A");
  635. git("stat a/0");
  636. git("commit");
  637. git("status");
  638. chdir("../../");
  639. puts("testing done");
  640. return 0;
  641. }
  642.  
  643. self> git
  644. Initialized empty Git repository in ~/CCR/UserFiles/Mobile C/Git/self/a/.git
  645. git_libgit2_init() = 3
  646. git_repository_head_unborn(repo) = 1
  647. looking up tree
  648. attemting to commit
  649. testing
  650. Initialized empty Git repository in ~/CCR/UserFiles/Mobile C/Git/self/a/0/.git
  651. git_libgit2_init() = 3
  652. git_repository_head_unborn(repo) = 1
  653. looking up tree
  654. attemting to commit
  655.  
  656.  
  657.  
  658.  
  659. git_libgit2_features() = 15
  660. git_libgit2_init() = 3
  661. File Path: b/l
  662. Stage: 0
  663. Blob SHA: e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
  664. File Mode: 0100644
  665. File Size: 0 bytes
  666. Dev/Inode: 0/1962460
  667. UID/GID: 501/501
  668. ctime: 1532334385
  669. mtime: 1532334385
  670.  
  671. File Path: test
  672. Stage: 0
  673. Blob SHA: e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
  674. File Mode: 0100644
  675. File Size: 0 bytes
  676. Dev/Inode: 0/1962458
  677. UID/GID: 501/501
  678. ctime: 1532334385
  679. mtime: 1532334385
  680.  
  681. git_libgit2_init() = 3
  682. git_repository_head_unborn(repo) = 0
  683. aquiring reference
  684. git_reference_name_to_id(&parent_id,repo,"HEAD") = 0 (none)
  685. looking up reference
  686. git_commit_lookup(&parent,repo,&parent_id) = 0 (none)
  687. attemting to commit
  688. SIGSEGV on thread : 1090547712
  689. 0>
  690.  
  691. #include <git2.h>
  692. #include <unistd.h>
  693. #include <stdio.h>
  694.  
  695. #define giterr(x) { printf("%s = %d (%s)n", #x, x, giterr_last()?giterr_last()->message:"none"); }
  696.  
  697.  
  698. #define giterror(...) {
  699. printf("error: " __VA_ARGS__);
  700. printf(" (%s)", giterr_last()?giterr_last()->message:"none");
  701. printf("n");
  702. return -2;
  703. }
  704.  
  705. int main(void)
  706. {
  707. int ret = 0, retg = 0;
  708. git_repository *repo;
  709. git_signature *sig;
  710. git_index *index;
  711. git_oid tree_id, commit_id;
  712. git_tree *tree;
  713. git_oid parent_id;
  714. git_commit *parent;
  715. ret = git_libgit2_init();
  716. giterr(ret)
  717. ret = chdir("a/0");
  718. giterr(ret)
  719. ret = git_repository_open(&repo, ".");
  720. giterr(ret)
  721. if (ret < 0) {
  722. git_libgit2_shutdown();
  723. giterror("Could not open repository");
  724. }
  725. ret = git_signature_default(&sig, repo);
  726. giterr(ret)
  727. if (ret < 0) {
  728. puts("Failed to obtain default signature, attempting to create new signature");
  729. ret = git_signature_new(&sig, "null","null@gmail.com",0,0);
  730. giterr(ret)
  731. if (ret < 0) {
  732. git_signature_free(sig); // returns void
  733. git_repository_free(repo); // returns void
  734. git_libgit2_shutdown();
  735. giterror("Unable to create a commit signature.n%s",
  736. "Perhaps 'user.name' and 'user.email' are not set");
  737. }
  738. }
  739. ret = git_repository_index(&index, repo);
  740. giterr(ret)
  741. if (ret < 0) {
  742. git_index_free(index); // returns void
  743. git_signature_free(sig); // returns void
  744. git_repository_free(repo); // returns void
  745. git_libgit2_shutdown();
  746. giterror("Could not open repository index", NULL);
  747. }
  748.  
  749. ret = git_index_write_tree(&tree_id, index);
  750. giterr(ret)
  751. if (ret < 0) {
  752. git_index_free(index); // returns void
  753. git_tree_free(tree); // returns void
  754. git_signature_free(sig); // returns void
  755. git_repository_free(repo); // returns void
  756. git_libgit2_shutdown();
  757. giterror("Unable to write initial tree from index", NULL);
  758. }
  759. git_index_free(index); // returns void
  760. retg = git_repository_head_unborn(repo);
  761. giterr(retg)
  762. if (retg == 1) {
  763. ret = git_tree_lookup(&tree, repo, &tree_id);
  764. giterr(ret)
  765. if (ret < 0) {
  766. git_tree_free(tree); // returns void
  767. git_signature_free(sig); // returns void
  768. git_repository_free(repo); // returns void
  769. git_libgit2_shutdown();
  770. giterror("Could not look up initial tree", NULL);
  771. }
  772. ret = git_commit_create_v(&commit_id, repo, "HEAD", sig, sig, NULL, "Initial commit", tree, 0);
  773. giterr(ret)
  774. if (ret < 0) {
  775. git_tree_free(tree); // returns void
  776. git_signature_free(sig); // returns void
  777. git_repository_free(repo); // returns void
  778. git_libgit2_shutdown(); // returns void
  779. giterror("Could not create the initial commit (%d)", ret);
  780. }
  781. }
  782. else if (retg == 0) {
  783. ret = git_reference_name_to_id(&parent_id, repo, "HEAD");
  784. giterr(ret)
  785. if (ret < 0) {
  786. git_tree_free(tree); // returns void
  787. git_signature_free(sig); // returns void
  788. git_repository_free(repo); // returns void
  789. git_libgit2_shutdown(); // returns void
  790. giterror("Cannot convert reference to id (%d)", ret);
  791. }
  792. ret = git_commit_lookup(&parent, repo, &parent_id);
  793. giterr(ret)
  794. if (ret < 0) {
  795. git_commit_free(parent); // returns void
  796. git_tree_free(tree); // returns void
  797. git_signature_free(sig); // returns void
  798. git_repository_free(repo); // returns void
  799. git_libgit2_shutdown();
  800. giterror("Cannot look up commit (%d)", ret);
  801. }
  802. puts("committing");
  803. giterr(git_commit_tree(&tree, parent));
  804. ret = git_commit_create_v(&commit_id, repo, "HEAD", sig, sig, NULL, "-a", tree, 1, parent, NULL);
  805. puts("committed");
  806. giterr(ret)
  807. if (ret < 0) {
  808. git_commit_free(parent); // returns void
  809. git_tree_free(tree); // returns void
  810. git_signature_free(sig); // returns void
  811. git_repository_free(repo); // returns void
  812. git_libgit2_shutdown();
  813. giterror("Could not create the initial commit (%d)", ret);
  814. }
  815. // seg fault
  816. }
  817. ret = chdir("../../");
  818. giterr(ret)
  819. git_tree_free(tree);
  820. git_signature_free(sig);
  821. git_repository_free(repo);
  822. ret = git_libgit2_shutdown();
  823. giterr(ret)
  824. return 0;
  825. }
  826.  
  827. ret = 3 (none)
  828. ret = 0 (none)
  829. ret = 0 (none)
  830. ret = -3 (config value 'user.name' was not found)
  831. Failed to obtain default signature, attempting to create new signature
  832. ret = 0 (config value 'user.name' was not found)
  833. ret = 0 (config value 'user.name' was not found)
  834. ret = 0 (none)
  835. retg = 0 (none)
  836. ret = 0 (none)
  837. ret = 0 (none)
  838. committing
  839. ret = 0 (none)
  840. committed
  841. ret = 0 (none)
  842. ret = 0 (none)
Add Comment
Please, Sign In to add comment