diff --git a/docs/ko/reference/Commit/Methods/amend.md b/docs/ko/reference/Commit/Methods/amend.md
new file mode 100644
index 0000000..d324faa
--- /dev/null
+++ b/docs/ko/reference/Commit/Methods/amend.md
@@ -0,0 +1,121 @@
+# amend
+
+입력한 값을 사용해서 이 기존 커밋을 수정해요
+
+이 메서드는 기존 커밋과 완전히 동일하지만 값들이 업데이트된 새 커밋을 만들어요. 새 커밋은 이전 커밋과 동일한 부모를 가져요.
+
+## 시그니처
+
+```ts
+class Commit {
+ amend(options?: AmendOptions, tree?: Tree): string;
+}
+```
+
+### 파라미터
+
+
+ -
+ optionsnull | AmendOptions
+
+ 커밋을 수정하기 위한 옵션이에요.
+
+ -
+ authorSignaturePayload
+
+ 작성자 서명이에요.
+
+ -
+ email필수 · string
+
+ 서명에 사용되는 이메일이에요.
+
+ -
+ name필수 · string
+
+ 서명에 사용되는 이름이에요.
+
+ -
+ timeOptionsSignatureTimeOptions
+
+
+ -
+ offsetnumber
+
+ 시간대 오프셋(분 단위)이에요.
+
+ -
+ timestamp필수 · number
+
+ 에포크부터의 시간(초 단위)이에요.
+
+
+
+
+
+ -
+ committerSignaturePayload
+
+ 커미터 서명이에요.
+
+ -
+ email필수 · string
+
+ 서명에 사용되는 이메일이에요.
+
+ -
+ name필수 · string
+
+ 서명에 사용되는 이름이에요.
+
+ -
+ timeOptionsSignatureTimeOptions
+
+
+ -
+ offsetnumber
+
+ 시간대 오프셋(분 단위)이에요.
+
+ -
+ timestamp필수 · number
+
+ 에포크부터의 시간(초 단위)이에요.
+
+
+
+
+
+ -
+ messagestring
+
+ 이 커밋의 전체 메시지에요.
+
+ -
+ messageEncodingstring
+
+ 커밋 메시지에 사용할 인코딩이에요. 표준 인코딩 이름으로 표현해요. 예: "UTF-8"이에요. NULL이면 인코딩 헤더를 쓰지 않고 UTF-8로 간주해요.
+
+ -
+ updateRefstring
+
+ NULL이 아니면 이 커밋을 가리키도록 업데이트할 참조 이름이에요. 참조가 직접 참조가 아니면 직접 참조로 해석돼요. 현재 브랜치의 HEAD를 이 커밋을 가리키도록 업데이트하려면 "HEAD"를 사용해요. 참조가 아직 없으면 새로 만들어지고, 이미 있으면 이 브랜치의 최신 커밋이 첫 번째 부모여야 해요.
+
+
+
+ -
+ treenull | Tree
+
+ 커밋을 수정할 때 사용할 트리예요.
+
+
+
+### 반환 값
+
+
+ -
+ string
+
+ 수정된 커밋의 ID(SHA1)예요.
+
+
\ No newline at end of file
diff --git a/docs/reference/Commit/Methods/amend.md b/docs/reference/Commit/Methods/amend.md
new file mode 100644
index 0000000..eb6b7b5
--- /dev/null
+++ b/docs/reference/Commit/Methods/amend.md
@@ -0,0 +1,123 @@
+# amend
+
+Amend this existing commit with all non-nullable values
+
+This creates a new commit that is exactly the same as the old commit,
+except that any non-nullable values will be updated. The new commit has
+the same parents as the old commit.
+
+## Signature
+
+```ts
+class Commit {
+ amend(options?: AmendOptions, tree?: Tree): string;
+}
+```
+
+### Parameters
+
+
+
+### Returns
+
+
\ No newline at end of file
diff --git a/index.d.ts b/index.d.ts
index c27342a..8dd323f 100644
--- a/index.d.ts
+++ b/index.d.ts
@@ -547,6 +547,23 @@ export declare class Commit {
* @returns Commit time of a commit.
*/
time(): Date
+ /**
+ * Get the id of the tree pointed to by this commit.
+ *
+ * No attempts are made to fetch an object from the ODB.
+ *
+ * @category Commit/Methods
+ *
+ * @signature
+ * ```ts
+ * class Commit {
+ * treeId(): string;
+ * }
+ * ```
+ *
+ * @returns Get the id of the tree pointed to by a commit.
+ */
+ treeId(): string
/**
* Get the tree pointed to by a commit.
*
@@ -577,6 +594,27 @@ export declare class Commit {
* @returns `GitObject` that casted from this commit.
*/
asObject(): GitObject
+ /**
+ * Amend this existing commit with all non-nullable values
+ *
+ * This creates a new commit that is exactly the same as the old commit,
+ * except that any non-nullable values will be updated. The new commit has
+ * the same parents as the old commit.
+ *
+ * @category Commit/Methods
+ *
+ * @signature
+ * ```ts
+ * class Commit {
+ * amend(options?: AmendOptions, tree?: Tree): string;
+ * }
+ * ```
+ *
+ * @param {AmendOptions} [options] - Options for amending commit.
+ * @param {Tree} [tree] - Tree to use for amending commit.
+ * @returns ID(SHA1) of amended commit.
+ */
+ amend(options?: AmendOptions | undefined | null, tree?: Tree | undefined | null): string
/**
* Get the author of this commit, using the mailmap to map it to the canonical name and email.
*
@@ -5254,6 +5292,30 @@ export interface AddMailmapEntryData {
replaceEmail: string
}
+export interface AmendOptions {
+ /**
+ * If not NULL, name of the reference that will be updated to point to this commit.
+ * If the reference is not direct, it will be resolved to a direct reference.
+ * Use "HEAD" to update the HEAD of the current branch and make it point to this commit.
+ *
+ * If the reference doesn't exist yet, it will be created.
+ * If it does exist, the first parent must be the tip of this branch.
+ */
+ updateRef?: string
+ /** Signature for author. */
+ author?: SignaturePayload
+ /** Signature for committer. */
+ committer?: SignaturePayload
+ /** Full message for this commit */
+ message?: string
+ /**
+ * The encoding for the message in the commit, represented with a standard encoding name.
+ * E.g. "UTF-8".
+ * If NULL, no encoding header is written and UTF-8 is assumed.
+ */
+ messageEncoding?: string
+}
+
/**
* - `Unspecified` : Use the setting from the remote's configuration
* - `Auto` : Ask the server for tags pointing to objects we're already downloading
diff --git a/src/commit.rs b/src/commit.rs
index 4d51122..48c0959 100644
--- a/src/commit.rs
+++ b/src/commit.rs
@@ -31,6 +31,28 @@ pub struct CommitOptions {
pub signature_field: Option,
}
+#[napi(object)]
+#[derive(Default)]
+pub struct AmendOptions {
+ /// If not NULL, name of the reference that will be updated to point to this commit.
+ /// If the reference is not direct, it will be resolved to a direct reference.
+ /// Use "HEAD" to update the HEAD of the current branch and make it point to this commit.
+ ///
+ /// If the reference doesn't exist yet, it will be created.
+ /// If it does exist, the first parent must be the tip of this branch.
+ pub update_ref: Option,
+ /// Signature for author.
+ pub author: Option,
+ /// Signature for committer.
+ pub committer: Option,
+ /// Full message for this commit
+ pub message: Option,
+ /// The encoding for the message in the commit, represented with a standard encoding name.
+ /// E.g. "UTF-8".
+ /// If NULL, no encoding header is written and UTF-8 is assumed.
+ pub message_encoding: Option,
+}
+
pub(crate) enum CommitInner {
Repo(SharedReference>),
Owned(git2::Commit<'static>),
@@ -246,6 +268,50 @@ impl Commit {
inner: ObjectInner::Owned(obj),
}
}
+
+ #[napi]
+ /// Amend this existing commit with all non-nullable values
+ ///
+ /// This creates a new commit that is exactly the same as the old commit,
+ /// except that any non-nullable values will be updated. The new commit has
+ /// the same parents as the old commit.
+ ///
+ /// @category Commit/Methods
+ ///
+ /// @signature
+ /// ```ts
+ /// class Commit {
+ /// amend(options?: AmendOptions, tree?: Tree): string;
+ /// }
+ /// ```
+ ///
+ /// @param {AmendOptions} [options] - Options for amending commit.
+ /// @param {Tree} [tree] - Tree to use for amending commit.
+ /// @returns ID(SHA1) of amended commit.
+ pub fn amend(&self, options: Option, tree: Option<&Tree>) -> crate::Result {
+ let opts = options.unwrap_or_default();
+ let update_ref = opts.update_ref;
+ let author = opts
+ .author
+ .and_then(|x| Signature::try_from(x).ok())
+ .and_then(|x| git2::Signature::try_from(x).ok());
+ let committer = opts
+ .committer
+ .and_then(|x| Signature::try_from(x).ok())
+ .and_then(|x| git2::Signature::try_from(x).ok());
+ let message = opts.message;
+ let message_encoding = opts.message_encoding;
+
+ let oid = self.inner.amend(
+ update_ref.as_deref(),
+ author.as_ref(),
+ committer.as_ref(),
+ message_encoding.as_deref(),
+ message.as_deref(),
+ tree.map(|x| x.inner.deref()),
+ )?;
+ Ok(oid.to_string())
+ }
}
#[napi]