isomorphic-git 1.27.3 → 1.29.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.d.ts CHANGED
@@ -641,6 +641,14 @@ export type HeadStatus = 0 | 1;
641
641
  export type WorkdirStatus = 0 | 1 | 2;
642
642
  export type StageStatus = 0 | 1 | 2 | 3;
643
643
  export type StatusRow = [string, 0 | 1, 0 | 1 | 2, 0 | 1 | 2 | 3];
644
+ /**
645
+ * the type of stash ops
646
+ */
647
+ export type StashOp = "push" | "drop" | "pop" | "apply" | "list" | "clear";
648
+ /**
649
+ * - when compare WORDIR to HEAD, 'remove' could mean 'untracked'
650
+ */
651
+ export type StashChangeType = "add" | "unknown" | "remove" | "equal" | "modify";
644
652
  export type ClientRef = {
645
653
  /**
646
654
  * The name of the ref
@@ -724,6 +732,7 @@ declare namespace index {
724
732
  export { listBranches };
725
733
  export { listFiles };
726
734
  export { listNotes };
735
+ export { listRefs };
727
736
  export { listRemotes };
728
737
  export { listServerRefs };
729
738
  export { listTags };
@@ -755,6 +764,7 @@ declare namespace index {
755
764
  export { writeRef };
756
765
  export { writeTag };
757
766
  export { writeTree };
767
+ export { stash };
758
768
  }
759
769
  export var Errors: Readonly<{
760
770
  __proto__: null;
@@ -1984,6 +1994,28 @@ export function listNotes({ fs, dir, gitdir, ref, cache, }: {
1984
1994
  target: string;
1985
1995
  note: string;
1986
1996
  }[]>;
1997
+ /**
1998
+ * List refs
1999
+ *
2000
+ * @param {object} args
2001
+ * @param {FsClient} args.fs - a file system client
2002
+ * @param {string} [args.dir] - The [working tree](dir-vs-gitdir.md) directory path
2003
+ * @param {string} [args.gitdir=join(dir,'.git')] - [required] The [git directory](dir-vs-gitdir.md) path
2004
+ * @param {string} [args.filepath] - [required] The refs path to list
2005
+ *
2006
+ * @returns {Promise<Array<string>>} Resolves successfully with an array of ref names below the supplied `filepath`
2007
+ *
2008
+ * @example
2009
+ * let refs = await git.listRefs({ fs, dir: '/tutorial', filepath: 'refs/heads' })
2010
+ * console.log(refs)
2011
+ *
2012
+ */
2013
+ export function listRefs({ fs, dir, gitdir, filepath, }: {
2014
+ fs: CallbackFsClient | PromiseFsClient;
2015
+ dir?: string;
2016
+ gitdir?: string;
2017
+ filepath?: string;
2018
+ }): Promise<string[]>;
1987
2019
  /**
1988
2020
  * List remotes
1989
2021
  *
@@ -3059,6 +3091,65 @@ export function setConfig({ fs: _fs, dir, gitdir, path, value, append, }: {
3059
3091
  value: string | number | boolean | void;
3060
3092
  append?: boolean;
3061
3093
  }): Promise<void>;
3094
+ /**
3095
+ * stash api, supports {'push' | 'pop' | 'apply' | 'drop' | 'list' | 'clear'} StashOp
3096
+ * _note_,
3097
+ * - all stash operations are done on tracked files only with loose objects, no packed objects
3098
+ * - when op === 'push', both working directory and index (staged) changes will be stashed, tracked files only
3099
+ * - when op === 'push', message is optional, and only applicable when op === 'push'
3100
+ * - when op === 'apply | pop', the stashed changes will overwrite the working directory, no abort when conflicts
3101
+ *
3102
+ * @param {object} args
3103
+ * @param {FsClient} args.fs - [required] a file system client
3104
+ * @param {string} [args.dir] - [required] The [working tree](dir-vs-gitdir.md) directory path
3105
+ * @param {string} [args.gitdir=join(dir,'.git')] - [optional] The [git directory](dir-vs-gitdir.md) path
3106
+ * @param {'push' | 'pop' | 'apply' | 'drop' | 'list' | 'clear'} [args.op = 'push'] - [optional] name of stash operation, default to 'push'
3107
+ * @param {string} [args.message = ''] - [optional] message to be used for the stash entry, only applicable when op === 'push'
3108
+ * @param {number} [args.refIdx = 0] - [optional - Number] stash ref index of entry, only applicable when op === ['apply' | 'drop' | 'pop'], refIdx >= 0 and < num of stash pushed
3109
+ * @returns {Promise<string | void>} Resolves successfully when stash operations are complete
3110
+ *
3111
+ * @example
3112
+ * // stash changes in the working directory and index
3113
+ * let dir = '/tutorial'
3114
+ * await fs.promises.writeFile(`${dir}/a.txt`, 'original content - a')
3115
+ * await fs.promises.writeFile(`${dir}/b.js`, 'original content - b')
3116
+ * await git.add({ fs, dir, filepath: [`a.txt`,`b.txt`] })
3117
+ * let sha = await git.commit({
3118
+ * fs,
3119
+ * dir,
3120
+ * author: {
3121
+ * name: 'Mr. Stash',
3122
+ * email: 'mstasher@stash.com',
3123
+ * },
3124
+ * message: 'add a.txt and b.txt to test stash'
3125
+ * })
3126
+ * console.log(sha)
3127
+ *
3128
+ * await fs.promises.writeFile(`${dir}/a.txt`, 'stashed chang- a')
3129
+ * await git.add({ fs, dir, filepath: `${dir}/a.txt` })
3130
+ * await fs.promises.writeFile(`${dir}/b.js`, 'work dir change. not stashed - b')
3131
+ *
3132
+ * await git.stash({ fs, dir }) // default gitdir and op
3133
+ *
3134
+ * console.log(await git.status({ fs, dir, filepath: 'a.txt' })) // 'unmodified'
3135
+ * console.log(await git.status({ fs, dir, filepath: 'b.txt' })) // 'unmodified'
3136
+ *
3137
+ * const refLog = await git.stash({ fs, dir, op: 'list' })
3138
+ * console.log(refLog) // [{stash{#} message}]
3139
+ *
3140
+ * await git.stash({ fs, dir, op: 'apply' }) // apply the stash
3141
+ *
3142
+ * console.log(await git.status({ fs, dir, filepath: 'a.txt' })) // 'modified'
3143
+ * console.log(await git.status({ fs, dir, filepath: 'b.txt' })) // '*modified'
3144
+ */
3145
+ export function stash({ fs, dir, gitdir, op, message, refIdx, }: {
3146
+ fs: CallbackFsClient | PromiseFsClient;
3147
+ dir?: string;
3148
+ gitdir?: string;
3149
+ op?: "push" | "drop" | "pop" | "apply" | "list" | "clear";
3150
+ message?: string;
3151
+ refIdx?: number;
3152
+ }): Promise<string | void>;
3062
3153
  /**
3063
3154
  * Tell whether a file has been changed
3064
3155
  *
@@ -4581,6 +4672,10 @@ declare namespace NoCommitError {
4581
4672
  * @typedef {[string, HeadStatus, WorkdirStatus, StageStatus]} StatusRow
4582
4673
  */
4583
4674
  /**
4675
+ * @typedef {'push' | 'pop' | 'apply' | 'drop' | 'list' | 'clear'} StashOp the type of stash ops
4676
+ */
4677
+ /**
4678
+ * @typedef {'equal' | 'modify' | 'add' | 'remove' | 'unknown'} StashChangeType - when compare WORDIR to HEAD, 'remove' could mean 'untracked'
4584
4679
  * @typedef {Object} ClientRef
4585
4680
  * @property {string} ref The name of the ref
4586
4681
  * @property {string} oid The SHA-1 object id the ref points to