| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,104 @@ | |||
| 1 | + var nodegit = require('../'); | ||
| 2 | + var path = require('path'); | ||
| 3 | + var Promise = require('nodegit-promise'); | ||
| 4 | + var promisify = require('promisify-node'); | ||
| 5 | + var fse = promisify(require('fs-extra')); | ||
| 6 | + fse.ensureDir = promisify(fse.ensureDir); | ||
| 7 | + | ||
| 8 | + var normalizeOptions = require('../lib/util/normalize_options'); | ||
| 9 | + var ourFileName = 'ourNewFile.txt'; | ||
| 10 | + var ourFileContent = 'I like Toll Roads. I have an EZ-Pass!'; | ||
| 11 | + var ourBranchName = "ours"; | ||
| 12 | + | ||
| 13 | + var theirFileName = 'theirNewFile.txt'; | ||
| 14 | + var theirFileContent = "I'm skeptical about Toll Roads"; | ||
| 15 | + var theirBranchName = "theirs"; | ||
| 16 | + | ||
| 17 | + var repoDir = '../../newRepo'; | ||
| 18 | + | ||
| 19 | + var repository; | ||
| 20 | + var ourCommit; | ||
| 21 | + var theirCommit; | ||
| 22 | + var ourBranch; | ||
| 23 | + var theirBranch; | ||
| 24 | + | ||
| 25 | + var ourSignature = nodegit.Signature.create("Ron Paul", "RonPaul@TollRoadsRBest.info", 123456789, 60); | ||
| 26 | + var theirSignature = nodegit.Signature.create("Greg Abbott", "Gregggg@IllTollYourFace.us", 123456789, 60); | ||
| 27 | + | ||
| 28 | + fse.remove(path.resolve(__dirname, repoDir)) | ||
| 29 | + .then(function() { | ||
| 30 | + return fse.ensureDir(path.resolve(__dirname, repoDir)); | ||
| 31 | + }) | ||
| 32 | + .then(function() { | ||
| 33 | + return nodegit.Repository.init(path.resolve(__dirname, repoDir), 0); | ||
| 34 | + }) | ||
| 35 | + .then(function(repo) { | ||
| 36 | + repository = repo; | ||
| 37 | + return fse.writeFile(path.join(repository.workdir(), ourFileName), ourFileContent); | ||
| 38 | + }) | ||
| 39 | + .then(function() { | ||
| 40 | + return repository.openIndex(); | ||
| 41 | + }) | ||
| 42 | + .then(function(index) { | ||
| 43 | + index.read(1); | ||
| 44 | + index.addByPath(ourFileName); | ||
| 45 | + index.write() | ||
| 46 | + | ||
| 47 | + return index.writeTree(); | ||
| 48 | + }) | ||
| 49 | + .then(function(oid) { | ||
| 50 | + return repository.createCommit('HEAD', ourSignature, ourSignature, 'we made a commit', oid, []); | ||
| 51 | + }).then(function(commitOid) { | ||
| 52 | + | ||
| 53 | + return repository.getCommit(commitOid).then(function(commit) { | ||
| 54 | + ourCommit = commit; | ||
| 55 | + }).then(function() { | ||
| 56 | + return repository.createBranch(ourBranchName, commitOid).then(function(branch) { | ||
| 57 | + ourBranch = branch; | ||
| 58 | + return repository.createBranch(theirBranchName, commitOid); | ||
| 59 | + }); | ||
| 60 | + }); | ||
| 61 | + }).then(function(branch) { | ||
| 62 | + theirBranch = branch; | ||
| 63 | + | ||
| 64 | + return nodegit.Reference.lookup(repository, 'HEAD').then(function(head) { | ||
| 65 | + return head.symbolicSetTarget(theirBranch.name(), theirSignature, ""); | ||
| 66 | + }); | ||
| 67 | + }).then(function() { | ||
| 68 | + return fse.writeFile(path.join(repository.workdir(), theirFileName), theirFileContent); | ||
| 69 | + }) | ||
| 70 | + .then(function() { | ||
| 71 | + return repository.openIndex(); | ||
| 72 | + }) | ||
| 73 | + .then(function(index) { | ||
| 74 | + index.read(1); | ||
| 75 | + index.addByPath(theirFileName); | ||
| 76 | + index.write() | ||
| 77 | + | ||
| 78 | + return index.writeTree(); | ||
| 79 | + }) | ||
| 80 | + .then(function(oid) { | ||
| 81 | + return repository.createCommit('HEAD', theirSignature, theirSignature, 'they made a commit', oid, [ourCommit]); | ||
| 82 | + }) | ||
| 83 | + .then(function(commitOid) { | ||
| 84 | + return repository.getCommit(commitOid).then(function(commit) { | ||
| 85 | + theirCommit = commit; | ||
| 86 | + }).then(function() { | ||
| 87 | + return nodegit.Reference.lookup(repository, 'HEAD').then(function(head) { | ||
| 88 | + return head.symbolicSetTarget(ourBranch.name(), ourSignature, ""); | ||
| 89 | + }); | ||
| 90 | + }); | ||
| 91 | + }) | ||
| 92 | + .then(function() { | ||
| 93 | + return nodegit.Merge.commits(repository, ourCommit, theirCommit, new nodegit.MergeOptions()); | ||
| 94 | + }) | ||
| 95 | + .then(function(index) { | ||
| 96 | + index.write() | ||
| 97 | + return index.writeTreeTo(repository); | ||
| 98 | + }) | ||
| 99 | + .then(function(oid) { | ||
| 100 | + return repository.createCommit(ourBranch.name(), ourSignature, ourSignature, 'we merged their commit', oid, [ourCommit, theirCommit]); | ||
| 101 | + }) | ||
| 102 | + .done(function(commitId) { | ||
| 103 | + console.log('New Commit: ', commitId); | ||
| 104 | + }); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -630,9 +630,6 @@ | |||
| 630 | 630 | "isOptional": true | |
| 631 | 631 | } | |
| 632 | 632 | } | |
| 633 | - }, | ||
| 634 | - "git_index_write_tree_to": { | ||
| 635 | - "ignore": true | ||
| 636 | 633 | } | |
| 637 | 634 | } | |
| 638 | 635 | }, | |
@@ -668,15 +665,19 @@ | |||
| 668 | 665 | "git_merge_analysis": { | |
| 669 | 666 | "ignore": true | |
| 670 | 667 | }, | |
| 671 | - "git_merge_base": { | ||
| 672 | - "ignore": true | ||
| 673 | - }, | ||
| 674 | 668 | "git_merge_base_many": { | |
| 675 | 669 | "ignore": true | |
| 676 | 670 | }, | |
| 677 | 671 | "git_merge_base_octopus": { | |
| 678 | 672 | "ignore": true | |
| 679 | 673 | }, | |
| 674 | + "git_merge_commits": { | ||
| 675 | + "args": { | ||
| 676 | + "opts": { | ||
| 677 | + "isOptional": true | ||
| 678 | + } | ||
| 679 | + } | ||
| 680 | + }, | ||
| 680 | 681 | "git_merge_file": { | |
| 681 | 682 | "ignore": true | |
| 682 | 683 | }, | |
@@ -1027,6 +1028,16 @@ | |||
| 1027 | 1028 | }, | |
| 1028 | 1029 | "git_reference_next_name": { | |
| 1029 | 1030 | "ignore": true | |
| 1031 | + }, | ||
| 1032 | + "git_reference_symbolic_set_target": { | ||
| 1033 | + "args": { | ||
| 1034 | + "signature": { | ||
| 1035 | + "isOptional": true | ||
| 1036 | + }, | ||
| 1037 | + "log_message": { | ||
| 1038 | + "isOptional": true | ||
| 1039 | + } | ||
| 1040 | + } | ||
| 1030 | 1041 | } | |
| 1031 | 1042 | } | |
| 1032 | 1043 | }, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -261,6 +261,16 @@ | |||
| 261 | 261 | "git_odb_object_size", | |
| 262 | 262 | "git_odb_object_type" | |
| 263 | 263 | ] | |
| 264 | + ], | ||
| 265 | + [ | ||
| 266 | + "merge_head", | ||
| 267 | + [ | ||
| 268 | + "git_merge_head_free", | ||
| 269 | + "git_merge_head_from_fetchhead", | ||
| 270 | + "git_merge_head_from_id", | ||
| 271 | + "git_merge_head_from_ref", | ||
| 272 | + "git_merge_head_id" | ||
| 273 | + ] | ||
| 264 | 274 | ] | |
| 265 | 275 | ] | |
| 266 | 276 | }, | |
@@ -274,6 +284,15 @@ | |||
| 274 | 284 | "git_odb_object_size", | |
| 275 | 285 | "git_odb_object_type" | |
| 276 | 286 | ] | |
| 287 | + }, | ||
| 288 | + "merge": { | ||
| 289 | + "functions": [ | ||
| 290 | + "git_merge_head_free", | ||
| 291 | + "git_merge_head_from_fetchhead", | ||
| 292 | + "git_merge_head_from_id", | ||
| 293 | + "git_merge_head_from_ref", | ||
| 294 | + "git_merge_head_id" | ||
| 295 | + ] | ||
| 277 | 296 | } | |
| 278 | 297 | } | |
| 279 | 298 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments