refs: make verify_refname_available() virtual
[git.git] / test-fake-ssh.c
blob980de216e10990a6406cae6e0b023c5fee7de488
1 #include "git-compat-util.h"
2 #include "run-command.h"
3 #include "strbuf.h"
5 int main(int argc, char **argv)
7 const char *trash_directory = getenv("TRASH_DIRECTORY");
8 struct strbuf buf = STRBUF_INIT;
9 FILE *f;
10 int i;
11 const char *child_argv[] = { NULL, NULL };
13 /* First, print all parameters into $TRASH_DIRECTORY/ssh-output */
14 if (!trash_directory)
15 die("Need a TRASH_DIRECTORY!");
16 strbuf_addf(&buf, "%s/ssh-output", trash_directory);
17 f = fopen(buf.buf, "w");
18 if (!f)
19 die("Could not write to %s", buf.buf);
20 for (i = 0; i < argc; i++)
21 fprintf(f, "%s%s", i > 0 ? " " : "", i > 0 ? argv[i] : "ssh:");
22 fprintf(f, "\n");
23 fclose(f);
25 /* Now, evaluate the *last* parameter */
26 if (argc < 2)
27 return 0;
28 child_argv[0] = argv[argc - 1];
29 return run_command_v_opt(child_argv, RUN_USING_SHELL);