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 @@ -19,14 +19,17 @@ const FILE_MODES = {
19
19
20
20
export const commitChangesFromRepo = async ( {
21
21
base,
22
- repoDirectory = process . cwd ( ) ,
22
+ repoDirectory,
23
+ addDirectory,
23
24
log,
24
25
...otherArgs
25
26
} : CommitChangesFromRepoArgs ) : Promise < CommitFilesResult > => {
26
27
const ref = base ?. commit ?? "HEAD" ;
28
+ const resolvedRepoDirectory =
29
+ repoDirectory ?? ( await git . findRoot ( { fs, filepath : process . cwd ( ) } ) ) ;
27
30
const gitLog = await git . log ( {
28
31
fs,
29
- dir : repoDirectory ,
32
+ dir : resolvedRepoDirectory ,
30
33
ref,
31
34
depth : 1 ,
32
35
} ) ;
@@ -47,14 +50,14 @@ export const commitChangesFromRepo = async ({
47
50
} ;
48
51
await git . walk ( {
49
52
fs,
50
- dir : repoDirectory ,
53
+ dir : addDirectory ?? resolvedRepoDirectory ,
51
54
trees,
52
55
map : async ( filepath , [ commit , workdir ] ) => {
53
56
// Don't include ignored files
54
57
if (
55
58
await git . isIgnored ( {
56
59
fs,
57
- dir : repoDirectory ,
60
+ dir : resolvedRepoDirectory ,
58
61
filepath,
59
62
} )
60
63
) {
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