Skip to content

Commit f871f1e

Browse files
racgooseokju-na
andauthored
feat: add reflog feature with tests (#180)
Co-authored-by: seokju-na <seokju.me@gmail.com>
1 parent 131625d commit f871f1e

File tree

5 files changed

+1026
-0
lines changed

5 files changed

+1026
-0
lines changed

index.d.ts

Lines changed: 244 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2374,6 +2374,200 @@ export declare class Reference {
23742374
rename(newName: string, options?: RenameReferenceOptions | undefined | null): Reference
23752375
}
23762376

2377+
/** A class to represent a git reflog. */
2378+
export declare class Reflog {
2379+
/**
2380+
* Append a new entry to the reflog.
2381+
*
2382+
* @category Reflog/Methods
2383+
*
2384+
* @signature
2385+
* ```ts
2386+
* class Reflog {
2387+
* append(newOid: string, committer: Signature, msg?: string | null | undefined): void;
2388+
* }
2389+
* ```
2390+
*
2391+
* @param {string} newOid - New object ID (SHA1) for this reflog entry.
2392+
* @param {Signature} committer - Committer signature for this reflog entry.
2393+
* @param {string} [msg] - Optional message for this reflog entry.
2394+
* @throws Throws error if the OID is invalid or if appending fails.
2395+
*/
2396+
append(newOid: string, committer: Signature, msg?: string | undefined | null): void
2397+
/**
2398+
* Remove an entry from the reflog.
2399+
*
2400+
* @category Reflog/Methods
2401+
*
2402+
* @signature
2403+
* ```ts
2404+
* class Reflog {
2405+
* remove(i: number, rewritePreviousEntry?: boolean): void;
2406+
* }
2407+
* ```
2408+
*
2409+
* @param {number} i - Index of the entry to remove.
2410+
* @param {boolean} [rewritePreviousEntry] - Whether to rewrite the previous entry. Defaults to 'false'.
2411+
* @throws Throws error if the index is invalid or if removal fails.
2412+
*/
2413+
remove(i: number, rewritePreviousEntry?: boolean | undefined | null): void
2414+
/**
2415+
* Get a reflog entry by index.
2416+
*
2417+
* @category Reflog/Methods
2418+
*
2419+
* @signature
2420+
* ```ts
2421+
* class Reflog {
2422+
* get(i: number): ReflogEntry | null;
2423+
* }
2424+
* ```
2425+
*
2426+
* @param {number} i - Index of the entry to get.
2427+
* @returns Reflog entry at the given index. Returns `null` if the index is out of bounds.
2428+
*/
2429+
get(i: number): ReflogEntry | null
2430+
/**
2431+
* Get the number of entries in the reflog.
2432+
*
2433+
* @category Reflog/Methods
2434+
*
2435+
* @signature
2436+
* ```ts
2437+
* class Reflog {
2438+
* len(): number;
2439+
* }
2440+
* ```
2441+
*
2442+
* @returns Number of entries in the reflog.
2443+
*/
2444+
len(): number
2445+
/**
2446+
* Check if the reflog is empty.
2447+
*
2448+
* @category Reflog/Methods
2449+
*
2450+
* @signature
2451+
* ```ts
2452+
* class Reflog {
2453+
* isEmpty(): boolean;
2454+
* }
2455+
* ```
2456+
*
2457+
* @returns `true` if the reflog is empty, `false` otherwise.
2458+
*/
2459+
isEmpty(): boolean
2460+
/**
2461+
* Create an iterator over the entries in the reflog.
2462+
*
2463+
* @category Reflog/Methods
2464+
*
2465+
* @signature
2466+
* ```ts
2467+
* class Reflog {
2468+
* iter(): ReflogIter;
2469+
* }
2470+
* ```
2471+
*
2472+
* @returns Iterator over the reflog entries.
2473+
*/
2474+
iter(): ReflogIter
2475+
/**
2476+
* Write the reflog to disk.
2477+
*
2478+
* @category Reflog/Methods
2479+
*
2480+
* @signature
2481+
* ```ts
2482+
* class Reflog {
2483+
* write(): void;
2484+
* }
2485+
* ```
2486+
*
2487+
* @throws Throws error if writing fails.
2488+
*/
2489+
write(): void
2490+
}
2491+
2492+
/** A class to represent a git reflog entry. */
2493+
export declare class ReflogEntry {
2494+
/**
2495+
* Get the committer of this reflog entry.
2496+
*
2497+
* @category ReflogEntry/Methods
2498+
*
2499+
* @signature
2500+
* ```ts
2501+
* class ReflogEntry {
2502+
* committer(): Signature;
2503+
* }
2504+
* ```
2505+
*
2506+
* @returns Committer signature of this reflog entry.
2507+
*/
2508+
committer(): Signature
2509+
/**
2510+
* Get the new object ID (SHA1) of this reflog entry.
2511+
*
2512+
* @category ReflogEntry/Methods
2513+
*
2514+
* @signature
2515+
* ```ts
2516+
* class ReflogEntry {
2517+
* idNew(): string;
2518+
* }
2519+
* ```
2520+
*
2521+
* @returns New object ID (SHA1) of this reflog entry.
2522+
*/
2523+
idNew(): string
2524+
/**
2525+
* Get the old object ID (SHA1) of this reflog entry.
2526+
*
2527+
* @category ReflogEntry/Methods
2528+
*
2529+
* @signature
2530+
* ```ts
2531+
* class ReflogEntry {
2532+
* idOld(): string;
2533+
* }
2534+
* ```
2535+
*
2536+
* @returns Old object ID (SHA1) of this reflog entry.
2537+
*/
2538+
idOld(): string
2539+
/**
2540+
* Get the message of this reflog entry.
2541+
*
2542+
* @category ReflogEntry/Methods
2543+
*
2544+
* @signature
2545+
* ```ts
2546+
* class ReflogEntry {
2547+
* message(): string | null;
2548+
* }
2549+
* ```
2550+
*
2551+
* @returns Message of this reflog entry. Returns `null` if no message is present.
2552+
* @throws Throws error if the message is not valid utf-8.
2553+
*/
2554+
message(): string | null
2555+
}
2556+
2557+
/**
2558+
* An iterator over the entries in a reflog.
2559+
*
2560+
* This type extends JavaScript's `Iterator`, and so has the iterator helper
2561+
* methods. It may extend the upcoming TypeScript `Iterator` class in the future.
2562+
*
2563+
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator#iterator_helper_methods
2564+
* @see https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-6.html#iterator-helper-methods
2565+
*/
2566+
export declare class ReflogIter extends Iterator<ReflogEntry, void, void> {
2567+
2568+
next(value?: void): IteratorResult<ReflogEntry, void>
2569+
}
2570+
23772571
/**
23782572
* A class representing a [remote][1] of a git repository.
23792573
*
@@ -3785,6 +3979,56 @@ export declare class Repository {
37853979
* ```
37863980
*/
37873981
getReference(name: string): Reference
3982+
/**
3983+
* Lookup a reflog by its name.
3984+
*
3985+
* @category Repository/Methods
3986+
*
3987+
* @signature
3988+
* ```ts
3989+
* class Repository {
3990+
* reflog(name: string): Reflog;
3991+
* }
3992+
* ```
3993+
*
3994+
* @param {string} name - Name of the reference whose reflog to lookup (e.g., "HEAD", "refs/heads/main").
3995+
* @returns Reflog instance for the given reference name.
3996+
* @throws Throws error if the reflog does not exist or cannot be opened.
3997+
*/
3998+
reflog(name: string): Reflog
3999+
/**
4000+
* Rename a reflog.
4001+
*
4002+
* @category Repository/Methods
4003+
*
4004+
* @signature
4005+
* ```ts
4006+
* class Repository {
4007+
* reflogRename(oldName: string, newName: string): void;
4008+
* }
4009+
* ```
4010+
*
4011+
* @param {string} oldName - Old name of the reference.
4012+
* @param {string} newName - New name of the reference.
4013+
* @throws Throws error if renaming fails.
4014+
*/
4015+
reflogRename(oldName: string, newName: string): void
4016+
/**
4017+
* Delete a reflog.
4018+
*
4019+
* @category Repository/Methods
4020+
*
4021+
* @signature
4022+
* ```ts
4023+
* class Repository {
4024+
* reflogDelete(name: string): void;
4025+
* }
4026+
* ```
4027+
*
4028+
* @param {string} name - Name of the reference whose reflog to delete.
4029+
* @throws Throws error if deletion fails.
4030+
*/
4031+
reflogDelete(name: string): void
37884032
/**
37894033
* List all remotes for a given repository
37904034
*

index.js

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ pub mod object;
2323
pub mod oid;
2424
pub mod rebase;
2525
pub mod reference;
26+
pub mod reflog;
2627
pub mod remote;
2728
pub mod repository;
2829
pub mod revert;

0 commit comments

Comments
 (0)