UNPKG

5.56 kBTypeScriptView Raw
1import { Config, Disposable, Project } from "../index";
2
3/** Represents the underlying git operations performed by Atom. */
4export class GitRepository {
5 // Construction
6 /** Creates a new GitRepository instance. */
7 static open(path: string, options?: { refreshOnWindowFocus?: boolean | undefined }): GitRepository;
8
9 constructor(
10 path: string,
11 options?: {
12 refreshOnWindowFocus?: boolean | undefined;
13 config?: Config | undefined;
14 project?: Project | undefined;
15 },
16 );
17
18 // Lifecycle
19 /** Destroy this GitRepository object. */
20 destroy(): void;
21
22 /** Returns a boolean indicating if this repository has been destroyed. */
23 isDestroyed(): boolean;
24
25 // Event Subscription
26 /**
27 * Invoke the given callback when this GitRepository's destroy() method is
28 * invoked.
29 */
30 onDidDestroy(callback: () => void): Disposable;
31
32 /**
33 * Invoke the given callback when a specific file's status has changed. When
34 * a file is updated, reloaded, etc, and the status changes, this will be fired.
35 */
36 onDidChangeStatus(callback: (event: RepoStatusChangedEvent) => void): Disposable;
37
38 /** Invoke the given callback when a multiple files' statuses have changed. */
39 onDidChangeStatuses(callback: () => void): Disposable;
40
41 // Repository Details
42 /** A string indicating the type of version control system used by this repository. */
43 getType(): "git";
44
45 /** Returns the string path of the repository. */
46 getPath(): string;
47
48 /** Returns the string working directory path of the repository. */
49 getWorkingDirectory(): string;
50
51 /** Returns true if at the root, false if in a subfolder of the repository. */
52 isProjectAtRoot(): boolean;
53
54 /** Makes a path relative to the repository's working directory. */
55 relativize(): string;
56
57 /** Returns true if the given branch exists. */
58 hasBranch(branch: string): boolean;
59
60 /** Retrieves a shortened version of the HEAD reference value. */
61 getShortHead(path?: string): string;
62
63 /** Is the given path a submodule in the repository? */
64 isSubmodule(path: string): boolean;
65
66 /**
67 * Returns the number of commits behind the current branch is from the its
68 * upstream remote branch. The default reference is the HEAD.
69 * @param reference The branch reference name.
70 * @param path The path in the repository to get this ifnromation for, only
71 * needed if the repository contains submodules.
72 * @return Returns the number of commits behind the current branch is from its
73 * upstream remote branch.
74 */
75 getAheadBehindCount(reference: string, path?: string): { ahead: number; behind: number };
76
77 /**
78 * Get the cached ahead/behind commit counts for the current branch's
79 * upstream branch.
80 */
81 getCachedUpstreamAheadBehindCount(path?: string): { ahead: number; behind: number };
82
83 /** Returns the git configuration value specified by the key. */
84 getConfigValue(key: string, path?: string): string;
85
86 /** Returns the origin url of the repository. */
87 getOriginURL(path?: string): string;
88
89 /**
90 * Returns the upstream branch for the current HEAD, or null if there is no
91 * upstream branch for the current HEAD.
92 */
93 getUpstreamBranch(path?: string): string | null;
94
95 /** Gets all the local and remote references. */
96 getReferences(path?: string): { heads: string[]; remotes: string[]; tags: string[] };
97
98 /** Returns the current string SHA for the given reference. */
99 getReferenceTarget(reference: string, path?: string): string;
100
101 // Reading Status
102 /** Returns true if the given path is modified. */
103 isPathModified(path: string): boolean;
104
105 /** Returns true if the given path is new. */
106 isPathNew(path: string): boolean;
107
108 /** Is the given path ignored? */
109 isPathIgnored(path: string): boolean;
110
111 /** Get the status of a directory in the repository's working directory. */
112 getDirectoryStatus(path: string): number;
113
114 /** Get the status of a single path in the repository. */
115 getPathStatus(path: string): number;
116
117 /** Get the cached status for the given path. */
118 getCachedPathStatus(path: string): number | null;
119
120 /** Returns true if the given status indicates modification. */
121 isStatusModified(status: number): boolean;
122
123 /** Returns true if the given status indicates a new path. */
124 isStatusNew(status: number): boolean;
125
126 // Retrieving Diffs
127 /**
128 * Retrieves the number of lines added and removed to a path.
129 * This compares the working directory contents of the path to the HEAD version.
130 */
131 getDiffStats(path: string): { added: number; deleted: number };
132
133 /**
134 * Retrieves the line diffs comparing the HEAD version of the given path
135 * and the given text.
136 */
137 getLineDiffs(
138 path: string,
139 text: string,
140 ): Array<{ oldStart: number; newStart: number; oldLines: number; newLines: number }>;
141
142 // Checking Out
143 /**
144 * Restore the contents of a path in the working directory and index to the
145 * version at HEAD.
146 */
147 checkoutHead(path: string): boolean;
148
149 /** Checks out a branch in your repository. */
150 checkoutReference(reference: string, create: boolean): boolean;
151}
152
153export interface RepoStatusChangedEvent {
154 path: string;
155
156 /**
157 * This value can be passed to ::isStatusModified or ::isStatusNew to get more
158 * information.
159 */
160 pathStatus: number;
161}