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.
Files changed (3) hide show
  1. package/dist/index.js +15 -9
  2. package/package.json +1 -1
  3. 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
- const branch = await getCurrentBranch();
6863
- const isNew = await isNewBranch(remote);
6864
- const pushArgs = ["push"];
6865
- if (isNew) {
6866
- pushArgs.push("-u");
6867
- }
6868
- pushArgs.push(remote, branch);
6869
- if (args.length > 0) {
6870
- pushArgs.push(...args);
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "safe-push",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Git push safety checker - blocks pushes to forbidden areas",
5
5
  "type": "module",
6
6
  "bin": {
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
- const branch = await getCurrentBranch();
110
- const isNew = await isNewBranch(remote);
109
+ let pushArgs: string[];
111
110
 
112
- const pushArgs = ["push"];
111
+ // ユーザーがremote/refspecを明示的に指定したか判定
112
+ const hasUserRefspec = args.some((arg) => !arg.startsWith("-"));
113
113
 
114
- // 新規ブランチの場合は-uオプションを追加
115
- if (isNew) {
116
- pushArgs.push("-u");
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
- pushArgs.push(remote, branch);
132
+ pushArgs.push(remote, branch);
120
133
 
121
- // 追加の引数がある場合
122
- if (args.length > 0) {
123
- pushArgs.push(...args);
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 {