MCPcopy
hub / github.com/gitless-vcs/gitless / create_commit

Method create_commit

gitless/core.py:1180–1253  ·  view source on GitHub ↗

Record a new commit on this branch. Args: files: the (modified) files to commit. msg: the commit message. author: the author of the commit (defaults to the default author according to the repository's configuration). partials: list of files to commit partially.

(self, files, msg, author=None, partials=None)

Source from the content-addressed store, hash-verified

1178
1179
1180 def create_commit(self, files, msg, author=None, partials=None):
1181 """Record a new commit on this branch.
1182
1183 Args:
1184 files: the (modified) files to commit.
1185 msg: the commit message.
1186 author: the author of the commit (defaults to the default author
1187 according to the repository's configuration).
1188 partials: list of files to commit partially.
1189 """
1190 git_repo = self.gl_repo.git_repo
1191 if not author:
1192 author = git_repo.default_signature
1193
1194 index = self._index
1195 if index.conflicts:
1196 raise GlError('Unresolved conflicts')
1197
1198 # If file f is in the list of files to be committed => commit the working
1199 # version (or the staged version if f is in the list of partially committed
1200 # files) and clear the staged version.
1201 # If file f is not in the list of files to be committed => leave its staged
1202 # version (if any) intact.
1203
1204 if partials is None:
1205 partials = []
1206
1207 def get_tree_and_update_index():
1208
1209 def update():
1210 """Add/remove files to the index."""
1211 for f in files:
1212 assert not os.path.isabs(f)
1213 git_f = _get_git_path(f)
1214 if not os.path.exists(os.path.join(self.gl_repo.root, f)):
1215 index.remove(git_f)
1216 elif f not in partials:
1217 index.add(git_f)
1218
1219 # Update index to how it should look like after the commit
1220 partial_entries = {}
1221 with index:
1222 update()
1223 for f in partials:
1224 git_f = _get_git_path(f)
1225 partial_entries[f] = index._git_index[git_f]
1226
1227 # To create the commit tree with only the changes to the given files we:
1228 # (i) reset the index to HEAD,
1229 # (ii) update it with the changes to commit,
1230 # (iii) create a tree out of this modified index, and
1231 # (iv) discard the changes after being done.
1232 index.read_tree(git_repo.head.peel().tree)
1233 update()
1234 for f in partial_entries.keys():
1235 index.add(partial_entries[f])
1236
1237 tree_oid = index.write_tree()

Callers 2

_fuseMethod · 0.80
mainFunction · 0.80

Calls 1

GlErrorClass · 0.85

Tested by

no test coverage detected