safe-push 0.2.0 → 0.2.1
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/dist/index.js +15 -9
- package/package.json +1 -1
- package/src/git.ts +26 -11
package/dist/index.js
CHANGED
|
@@ -6859,15 +6859,21 @@ async function getDiffFiles(remote = "origin") {
|
|
|
6859
6859
|
`).filter(Boolean);
|
|
6860
6860
|
}
|
|
6861
6861
|
async function execPush(args = [], remote = "origin") {
|
|
6862
|
-
|
|
6863
|
-
const
|
|
6864
|
-
|
|
6865
|
-
|
|
6866
|
-
|
|
6867
|
-
|
|
6868
|
-
|
|
6869
|
-
|
|
6870
|
-
|
|
6862
|
+
let pushArgs;
|
|
6863
|
+
const hasUserRefspec = args.some((arg) => !arg.startsWith("-"));
|
|
6864
|
+
if (hasUserRefspec) {
|
|
6865
|
+
pushArgs = ["push", ...args];
|
|
6866
|
+
} else {
|
|
6867
|
+
const branch = await getCurrentBranch();
|
|
6868
|
+
const isNew = await isNewBranch(remote);
|
|
6869
|
+
pushArgs = ["push"];
|
|
6870
|
+
const hasSetUpstream = args.some((a) => a === "-u" || a === "--set-upstream");
|
|
6871
|
+
if (isNew || hasSetUpstream) {
|
|
6872
|
+
pushArgs.push("-u");
|
|
6873
|
+
}
|
|
6874
|
+
pushArgs.push(remote, branch);
|
|
6875
|
+
const remainingFlags = args.filter((a) => a !== "-u" && a !== "--set-upstream");
|
|
6876
|
+
pushArgs.push(...remainingFlags);
|
|
6871
6877
|
}
|
|
6872
6878
|
try {
|
|
6873
6879
|
const output = await execGit(pushArgs);
|
package/package.json
CHANGED
package/src/git.ts
CHANGED
|
@@ -106,21 +106,36 @@ export async function execPush(
|
|
|
106
106
|
args: string[] = [],
|
|
107
107
|
remote = "origin"
|
|
108
108
|
): Promise<{ success: boolean; output: string }> {
|
|
109
|
-
|
|
110
|
-
const isNew = await isNewBranch(remote);
|
|
109
|
+
let pushArgs: string[];
|
|
111
110
|
|
|
112
|
-
|
|
111
|
+
// ユーザーがremote/refspecを明示的に指定したか判定
|
|
112
|
+
const hasUserRefspec = args.some((arg) => !arg.startsWith("-"));
|
|
113
113
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
pushArgs
|
|
117
|
-
}
|
|
114
|
+
if (hasUserRefspec) {
|
|
115
|
+
// ユーザー指定のremote/refspecをそのまま使用
|
|
116
|
+
pushArgs = ["push", ...args];
|
|
117
|
+
} else {
|
|
118
|
+
// 自動でremote/branchを決定
|
|
119
|
+
const branch = await getCurrentBranch();
|
|
120
|
+
const isNew = await isNewBranch(remote);
|
|
121
|
+
|
|
122
|
+
pushArgs = ["push"];
|
|
123
|
+
|
|
124
|
+
// 新規ブランチ、またはユーザーが-uを指定した場合に追加
|
|
125
|
+
const hasSetUpstream = args.some(
|
|
126
|
+
(a) => a === "-u" || a === "--set-upstream"
|
|
127
|
+
);
|
|
128
|
+
if (isNew || hasSetUpstream) {
|
|
129
|
+
pushArgs.push("-u");
|
|
130
|
+
}
|
|
118
131
|
|
|
119
|
-
|
|
132
|
+
pushArgs.push(remote, branch);
|
|
120
133
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
134
|
+
// -u/--set-upstream以外のフラグを追加
|
|
135
|
+
const remainingFlags = args.filter(
|
|
136
|
+
(a) => a !== "-u" && a !== "--set-upstream"
|
|
137
|
+
);
|
|
138
|
+
pushArgs.push(...remainingFlags);
|
|
124
139
|
}
|
|
125
140
|
|
|
126
141
|
try {
|