Skip to content

Commit 2c78210

Browse files
authored
feat: add commit amend method (#161)
1 parent 6011aa3 commit 2c78210

File tree

4 files changed

+372
-0
lines changed

4 files changed

+372
-0
lines changed
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
# amend
2+
3+
입력한 값을 사용해서 이 기존 커밋을 수정해요
4+
5+
이 메서드는 기존 커밋과 완전히 동일하지만 값들이 업데이트된 새 커밋을 만들어요. 새 커밋은 이전 커밋과 동일한 부모를 가져요.
6+
7+
## 시그니처
8+
9+
```ts
10+
class Commit {
11+
amend(options?: AmendOptions, tree?: Tree): string;
12+
}
13+
```
14+
15+
### 파라미터
16+
17+
<ul class="param-ul">
18+
<li class="param-li param-li-root">
19+
<span class="param-name">options</span><span class="param-type">null | AmendOptions</span>
20+
<br>
21+
<p class="param-description">커밋을 수정하기 위한 옵션이에요.</p>
22+
<ul class="param-ul">
23+
<li class="param-li">
24+
<span class="param-name">author</span><span class="param-type">SignaturePayload</span>
25+
<br>
26+
<p class="param-description">작성자 서명이에요.</p>
27+
<ul class="param-ul">
28+
<li class="param-li">
29+
<span class="param-name">email</span><span class="param-required">필수</span>&nbsp;·&nbsp;<span class="param-type">string</span>
30+
<br>
31+
<p class="param-description">서명에 사용되는 이메일이에요.</p>
32+
</li>
33+
<li class="param-li">
34+
<span class="param-name">name</span><span class="param-required">필수</span>&nbsp;·&nbsp;<span class="param-type">string</span>
35+
<br>
36+
<p class="param-description">서명에 사용되는 이름이에요.</p>
37+
</li>
38+
<li class="param-li">
39+
<span class="param-name">timeOptions</span><span class="param-type">SignatureTimeOptions</span>
40+
<br>
41+
<ul class="param-ul">
42+
<li class="param-li">
43+
<span class="param-name">offset</span><span class="param-type">number</span>
44+
<br>
45+
<p class="param-description">시간대 오프셋(분 단위)이에요.</p>
46+
</li>
47+
<li class="param-li">
48+
<span class="param-name">timestamp</span><span class="param-required">필수</span>&nbsp;·&nbsp;<span class="param-type">number</span>
49+
<br>
50+
<p class="param-description">에포크부터의 시간(초 단위)이에요.</p>
51+
</li>
52+
</ul>
53+
</li>
54+
</ul>
55+
</li>
56+
<li class="param-li">
57+
<span class="param-name">committer</span><span class="param-type">SignaturePayload</span>
58+
<br>
59+
<p class="param-description">커미터 서명이에요.</p>
60+
<ul class="param-ul">
61+
<li class="param-li">
62+
<span class="param-name">email</span><span class="param-required">필수</span>&nbsp;·&nbsp;<span class="param-type">string</span>
63+
<br>
64+
<p class="param-description">서명에 사용되는 이메일이에요.</p>
65+
</li>
66+
<li class="param-li">
67+
<span class="param-name">name</span><span class="param-required">필수</span>&nbsp;·&nbsp;<span class="param-type">string</span>
68+
<br>
69+
<p class="param-description">서명에 사용되는 이름이에요.</p>
70+
</li>
71+
<li class="param-li">
72+
<span class="param-name">timeOptions</span><span class="param-type">SignatureTimeOptions</span>
73+
<br>
74+
<ul class="param-ul">
75+
<li class="param-li">
76+
<span class="param-name">offset</span><span class="param-type">number</span>
77+
<br>
78+
<p class="param-description">시간대 오프셋(분 단위)이에요.</p>
79+
</li>
80+
<li class="param-li">
81+
<span class="param-name">timestamp</span><span class="param-required">필수</span>&nbsp;·&nbsp;<span class="param-type">number</span>
82+
<br>
83+
<p class="param-description">에포크부터의 시간(초 단위)이에요.</p>
84+
</li>
85+
</ul>
86+
</li>
87+
</ul>
88+
</li>
89+
<li class="param-li">
90+
<span class="param-name">message</span><span class="param-type">string</span>
91+
<br>
92+
<p class="param-description">이 커밋의 전체 메시지에요.</p>
93+
</li>
94+
<li class="param-li">
95+
<span class="param-name">messageEncoding</span><span class="param-type">string</span>
96+
<br>
97+
<p class="param-description">커밋 메시지에 사용할 인코딩이에요. 표준 인코딩 이름으로 표현해요. 예: &quot;UTF-8&quot;이에요. NULL이면 인코딩 헤더를 쓰지 않고 UTF-8로 간주해요.</p>
98+
</li>
99+
<li class="param-li">
100+
<span class="param-name">updateRef</span><span class="param-type">string</span>
101+
<br>
102+
<p class="param-description">NULL이 아니면 이 커밋을 가리키도록 업데이트할 참조 이름이에요. 참조가 직접 참조가 아니면 직접 참조로 해석돼요. 현재 브랜치의 HEAD를 이 커밋을 가리키도록 업데이트하려면 &quot;HEAD&quot;를 사용해요. 참조가 아직 없으면 새로 만들어지고, 이미 있으면 이 브랜치의 최신 커밋이 첫 번째 부모여야 해요.</p>
103+
</li>
104+
</ul>
105+
</li>
106+
<li class="param-li param-li-root">
107+
<span class="param-name">tree</span><span class="param-type">null | Tree</span>
108+
<br>
109+
<p class="param-description">커밋을 수정할 때 사용할 트리예요.</p>
110+
</li>
111+
</ul>
112+
113+
### 반환 값
114+
115+
<ul class="param-ul">
116+
<li class="param-li param-li-root">
117+
<span class="param-type">string</span>
118+
<br>
119+
<p class="param-description">수정된 커밋의 ID(SHA1)예요.</p>
120+
</li>
121+
</ul>
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
# amend
2+
3+
Amend this existing commit with all non-nullable values
4+
5+
This creates a new commit that is exactly the same as the old commit,
6+
except that any non-nullable values will be updated. The new commit has
7+
the same parents as the old commit.
8+
9+
## Signature
10+
11+
```ts
12+
class Commit {
13+
amend(options?: AmendOptions, tree?: Tree): string;
14+
}
15+
```
16+
17+
### Parameters
18+
19+
<ul class="param-ul">
20+
<li class="param-li param-li-root">
21+
<span class="param-name">options</span><span class="param-type">null | AmendOptions</span>
22+
<br>
23+
<p class="param-description">Options for amending commit.</p>
24+
<ul class="param-ul">
25+
<li class="param-li">
26+
<span class="param-name">author</span><span class="param-type">SignaturePayload</span>
27+
<br>
28+
<p class="param-description">Signature for author.</p>
29+
<ul class="param-ul">
30+
<li class="param-li">
31+
<span class="param-name">email</span><span class="param-required">required</span>&nbsp;·&nbsp;<span class="param-type">string</span>
32+
<br>
33+
<p class="param-description">Email on the signature.</p>
34+
</li>
35+
<li class="param-li">
36+
<span class="param-name">name</span><span class="param-required">required</span>&nbsp;·&nbsp;<span class="param-type">string</span>
37+
<br>
38+
<p class="param-description">Name on the signature.</p>
39+
</li>
40+
<li class="param-li">
41+
<span class="param-name">timeOptions</span><span class="param-type">SignatureTimeOptions</span>
42+
<br>
43+
<ul class="param-ul">
44+
<li class="param-li">
45+
<span class="param-name">offset</span><span class="param-type">number</span>
46+
<br>
47+
<p class="param-description">Timezone offset, in minutes</p>
48+
</li>
49+
<li class="param-li">
50+
<span class="param-name">timestamp</span><span class="param-required">required</span>&nbsp;·&nbsp;<span class="param-type">number</span>
51+
<br>
52+
<p class="param-description">Time in seconds, from epoch</p>
53+
</li>
54+
</ul>
55+
</li>
56+
</ul>
57+
</li>
58+
<li class="param-li">
59+
<span class="param-name">committer</span><span class="param-type">SignaturePayload</span>
60+
<br>
61+
<p class="param-description">Signature for committer.</p>
62+
<ul class="param-ul">
63+
<li class="param-li">
64+
<span class="param-name">email</span><span class="param-required">required</span>&nbsp;·&nbsp;<span class="param-type">string</span>
65+
<br>
66+
<p class="param-description">Email on the signature.</p>
67+
</li>
68+
<li class="param-li">
69+
<span class="param-name">name</span><span class="param-required">required</span>&nbsp;·&nbsp;<span class="param-type">string</span>
70+
<br>
71+
<p class="param-description">Name on the signature.</p>
72+
</li>
73+
<li class="param-li">
74+
<span class="param-name">timeOptions</span><span class="param-type">SignatureTimeOptions</span>
75+
<br>
76+
<ul class="param-ul">
77+
<li class="param-li">
78+
<span class="param-name">offset</span><span class="param-type">number</span>
79+
<br>
80+
<p class="param-description">Timezone offset, in minutes</p>
81+
</li>
82+
<li class="param-li">
83+
<span class="param-name">timestamp</span><span class="param-required">required</span>&nbsp;·&nbsp;<span class="param-type">number</span>
84+
<br>
85+
<p class="param-description">Time in seconds, from epoch</p>
86+
</li>
87+
</ul>
88+
</li>
89+
</ul>
90+
</li>
91+
<li class="param-li">
92+
<span class="param-name">message</span><span class="param-type">string</span>
93+
<br>
94+
<p class="param-description">Full message for this commit</p>
95+
</li>
96+
<li class="param-li">
97+
<span class="param-name">messageEncoding</span><span class="param-type">string</span>
98+
<br>
99+
<p class="param-description">The encoding for the message in the commit, represented with a standard encoding name. E.g. &quot;UTF-8&quot;. If NULL, no encoding header is written and UTF-8 is assumed.</p>
100+
</li>
101+
<li class="param-li">
102+
<span class="param-name">updateRef</span><span class="param-type">string</span>
103+
<br>
104+
<p class="param-description">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 &quot;HEAD&quot; to update the HEAD of the current branch and make it point to this commit. If the reference doesn&#39;t exist yet, it will be created. If it does exist, the first parent must be the tip of this branch.</p>
105+
</li>
106+
</ul>
107+
</li>
108+
<li class="param-li param-li-root">
109+
<span class="param-name">tree</span><span class="param-type">null | Tree</span>
110+
<br>
111+
<p class="param-description">Tree to use for amending commit.</p>
112+
</li>
113+
</ul>
114+
115+
### Returns
116+
117+
<ul class="param-ul">
118+
<li class="param-li param-li-root">
119+
<span class="param-type">string</span>
120+
<br>
121+
<p class="param-description">ID(SHA1) of amended commit.</p>
122+
</li>
123+
</ul>

index.d.ts

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,23 @@ export declare class Commit {
547547
* @returns Commit time of a commit.
548548
*/
549549
time(): Date
550+
/**
551+
* Get the id of the tree pointed to by this commit.
552+
*
553+
* No attempts are made to fetch an object from the ODB.
554+
*
555+
* @category Commit/Methods
556+
*
557+
* @signature
558+
* ```ts
559+
* class Commit {
560+
* treeId(): string;
561+
* }
562+
* ```
563+
*
564+
* @returns Get the id of the tree pointed to by a commit.
565+
*/
566+
treeId(): string
550567
/**
551568
* Get the tree pointed to by a commit.
552569
*
@@ -577,6 +594,27 @@ export declare class Commit {
577594
* @returns `GitObject` that casted from this commit.
578595
*/
579596
asObject(): GitObject
597+
/**
598+
* Amend this existing commit with all non-nullable values
599+
*
600+
* This creates a new commit that is exactly the same as the old commit,
601+
* except that any non-nullable values will be updated. The new commit has
602+
* the same parents as the old commit.
603+
*
604+
* @category Commit/Methods
605+
*
606+
* @signature
607+
* ```ts
608+
* class Commit {
609+
* amend(options?: AmendOptions, tree?: Tree): string;
610+
* }
611+
* ```
612+
*
613+
* @param {AmendOptions} [options] - Options for amending commit.
614+
* @param {Tree} [tree] - Tree to use for amending commit.
615+
* @returns ID(SHA1) of amended commit.
616+
*/
617+
amend(options?: AmendOptions | undefined | null, tree?: Tree | undefined | null): string
580618
/**
581619
* Get the author of this commit, using the mailmap to map it to the canonical name and email.
582620
*
@@ -5254,6 +5292,30 @@ export interface AddMailmapEntryData {
52545292
replaceEmail: string
52555293
}
52565294

5295+
export interface AmendOptions {
5296+
/**
5297+
* If not NULL, name of the reference that will be updated to point to this commit.
5298+
* If the reference is not direct, it will be resolved to a direct reference.
5299+
* Use "HEAD" to update the HEAD of the current branch and make it point to this commit.
5300+
*
5301+
* If the reference doesn't exist yet, it will be created.
5302+
* If it does exist, the first parent must be the tip of this branch.
5303+
*/
5304+
updateRef?: string
5305+
/** Signature for author. */
5306+
author?: SignaturePayload
5307+
/** Signature for committer. */
5308+
committer?: SignaturePayload
5309+
/** Full message for this commit */
5310+
message?: string
5311+
/**
5312+
* The encoding for the message in the commit, represented with a standard encoding name.
5313+
* E.g. "UTF-8".
5314+
* If NULL, no encoding header is written and UTF-8 is assumed.
5315+
*/
5316+
messageEncoding?: string
5317+
}
5318+
52575319
/**
52585320
* - `Unspecified` : Use the setting from the remote's configuration
52595321
* - `Auto` : Ask the server for tags pointing to objects we're already downloading

0 commit comments

Comments
 (0)