File tree Expand file tree Collapse file tree 4 files changed +39
-5
lines changed Expand file tree Collapse file tree 4 files changed +39
-5
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ " @changesets/ghcommit " : minor
3
+ ---
4
+
5
+ Introduce ` addDirectory ` option for ` commitChangesFromRepo ` to allow users to
6
+ specify a subdirectory of the git repository that should be used to add files
7
+ from, rather then adding all changed files.
8
+
9
+ This is useful when trying to emulate the behavior of running ` git add . `
10
+ from a subdirectory of the repository.
Original file line number Diff line number Diff line change
1
+ ---
2
+ " @changesets/ghcommit " : minor
3
+ ---
4
+
5
+ Automatically find root in ` commitChangesFromRepo `
6
+ when ` repoDirectory ` is unspecified.
7
+
8
+ While this does result in a behavioral change for an existing argument,
9
+ it's considered non-breaking as before ` commitChangesFromRepo ` would just not
10
+ work when run from a subdirectory of a repo when ` repoDirectory ` was not
11
+ specified.
Original file line number Diff line number Diff line change @@ -9,14 +9,17 @@ import {
9
9
10
10
export const commitChangesFromRepo = async ( {
11
11
base,
12
- repoDirectory = process . cwd ( ) ,
12
+ repoDirectory,
13
+ addDirectory,
13
14
log,
14
15
...otherArgs
15
16
} : CommitChangesFromRepoArgs ) : Promise < CommitFilesResult > => {
16
17
const ref = base ?. commit ?? "HEAD" ;
18
+ const resolvedRepoDirectory =
19
+ repoDirectory ?? ( await git . findRoot ( { fs, filepath : process . cwd ( ) } ) ) ;
17
20
const gitLog = await git . log ( {
18
21
fs,
19
- dir : repoDirectory ,
22
+ dir : resolvedRepoDirectory ,
20
23
ref,
21
24
depth : 1 ,
22
25
} ) ;
@@ -37,7 +40,7 @@ export const commitChangesFromRepo = async ({
37
40
} ;
38
41
await git . walk ( {
39
42
fs,
40
- dir : repoDirectory ,
43
+ dir : addDirectory ?? resolvedRepoDirectory ,
41
44
trees,
42
45
map : async ( filepath , [ commit , workdir ] ) => {
43
46
const prevOid = await commit ?. oid ( ) ;
@@ -50,7 +53,7 @@ export const commitChangesFromRepo = async ({
50
53
if (
51
54
await git . isIgnored ( {
52
55
fs,
53
- dir : repoDirectory ,
56
+ dir : resolvedRepoDirectory ,
54
57
filepath,
55
58
} )
56
59
) {
Original file line number Diff line number Diff line change @@ -107,7 +107,17 @@ export interface CommitChangesFromRepoArgs extends CommitFilesBasedArgs {
107
107
/**
108
108
* The root of the repository.
109
109
*
110
- * @default process.cwd()
110
+ * When unspecified, the root of the repository will be found by recursively
111
+ * searching for the `.git` directory from the current working directory.
111
112
*/
112
113
repoDirectory ?: string ;
114
+ /**
115
+ * Which directory to add the files from.
116
+ *
117
+ * Useful for monorepos where you want to add files from a specific directory only.
118
+ *
119
+ * Defaults to resolved value as {@link repoDirectory},
120
+ * which will add all changed files in the repository.
121
+ */
122
+ addDirectory ?: string ;
113
123
}
You can’t perform that action at this time.
0 commit comments