MCPcopy Create free account
hub / github.com/isomorphic-git/isomorphic-git / writeObject

Function writeObject

src/api/writeObject.js:78–125  ·  view source on GitHub ↗
({
  fs: _fs,
  dir,
  gitdir = join(dir, '.git'),
  type,
  object,
  format = 'parsed',
  oid,
  encoding = undefined,
})

Source from the content-addressed store, hash-verified

76 *
77 */
78export async function writeObject({
79 fs: _fs,
80 dir,
81 gitdir = join(dir, '.git'),
82 type,
83 object,
84 format = 'parsed',
85 oid,
86 encoding = undefined,
87}) {
88 try {
89 const fs = new FileSystem(_fs)
90 const updatedGitdir = await discoverGitdir({ fsp: fs, dotgit: gitdir })
91 // Convert object to buffer
92 if (format === 'parsed') {
93 switch (type) {
94 case 'commit':
95 object = GitCommit.from(object).toObject()
96 break
97 case 'tree':
98 object = GitTree.from(object).toObject()
99 break
100 case 'blob':
101 object = Buffer.from(object, encoding)
102 break
103 case 'tag':
104 object = GitAnnotatedTag.from(object).toObject()
105 break
106 default:
107 throw new ObjectTypeError(oid || '', type, 'blob|commit|tag|tree')
108 }
109 // GitObjectManager does not know how to serialize content, so we tweak that parameter before passing it.
110 format = 'content'
111 }
112 oid = await _writeObject({
113 fs,
114 gitdir: updatedGitdir,
115 type,
116 object,
117 oid,
118 format,
119 })
120 return oid
121 } catch (err) {
122 err.caller = 'git.writeObject'
123 throw err
124 }
125}

Callers

nothing calls this directly

Calls 5

joinFunction · 0.90
discoverGitdirFunction · 0.90
_writeObjectFunction · 0.90
toObjectMethod · 0.45
fromMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…