commit 433eb77d4f00be3e4a69641f7a61b4e5c6935a15 from: Stefan Sperling date: Mon Jun 03 08:21:36 2024 UTC reintroduce the 'got init' command as an alternative to 'gotadmin init' New users trying out Got for the first time have reported trouble with finding a way to create a new repository, based on their assumption that Got works like Git which provides a 'git init' command. It doesn't cost us much effort to keep this command available in both programs to make discovery a bit easier for new users coming from Git. commit - 2b1d417da7256f4a2ca5a1e7d20a9ba901dec893 commit + 433eb77d4f00be3e4a69641f7a61b4e5c6935a15 blob - 0e665f95953ac4cc1f0f6a97331b5de8d00fb0bc blob + 8c5b5a75328351dabed1b36f8461032cb1adeee8 --- got/got.1 +++ got/got.1 @@ -62,6 +62,50 @@ The commands for .Nm are as follows: .Bl -tag -width checkout +.It Cm init Oo Fl b Ar branch Oc Ar repository-path +Create a new empty repository at the specified +.Ar repository-path . +.Pp +After +.Cm got init , +the new repository must be populated before +.Cm got checkout +can be used. +The +.Cm got import +command can be used to populate the new repository with data from +a local directory. +Alternatively, on a server running +.Xr gotd 8 , +the new repository can be made available to +.Xr got 1 +or +.Xr git 1 +clients by adding the repository to +.Xr gotd.conf 5 +and restarting +.Xr gotd 8 . +Clients may then clone the new repository from the server, populate the cloned +repository, and then populate the new repository on the server via +.Cm got send +or +.Cm git push . +.Pp +The options for +.Cm got init +are as follows: +.Bl -tag -width Ds +.It Fl b Ar branch +Make the repository's HEAD reference point to the specified +.Ar branch +instead of the default branch +.Dq main . +.El +.Pp +The +.Cm got init +command is equivalent to +.Cm gotadmin init . .Tg im .It Xo .Cm import @@ -3855,7 +3899,7 @@ a new Git repository could be created and populated wi e.g. from a temporary CVS checkout located at .Pa /tmp/src : .Pp -.Dl $ gotadmin init /var/git/src.git +.Dl $ got init /var/git/src.git .Dl $ got import -r /var/git/src.git -I CVS -I obj /tmp/src .Pp Check out a work tree from the Git repository to /usr/src: blob - 90f25d11eb70d4f6a5db417cbf29dfcad7751db4 blob + 724bdeb9f769210987e3c67785f9758c2dc5b3cb --- got/got.c +++ got/got.c @@ -96,6 +96,7 @@ struct got_cmd { }; __dead static void usage(int, int); +__dead static void usage_init(void); __dead static void usage_import(void); __dead static void usage_clone(void); __dead static void usage_fetch(void); @@ -126,6 +127,7 @@ __dead static void usage_unstage(void); __dead static void usage_cat(void); __dead static void usage_info(void); +static const struct got_error* cmd_init(int, char *[]); static const struct got_error* cmd_import(int, char *[]); static const struct got_error* cmd_clone(int, char *[]); static const struct got_error* cmd_fetch(int, char *[]); @@ -157,6 +159,7 @@ static const struct got_error* cmd_cat(int, char *[]) static const struct got_error* cmd_info(int, char *[]); static const struct got_cmd got_commands[] = { + { "init", cmd_init, usage_init, "" }, { "import", cmd_import, usage_import, "im" }, { "clone", cmd_clone, usage_clone, "cl" }, { "fetch", cmd_fetch, usage_fetch, "fe" }, @@ -352,6 +355,64 @@ apply_unveil(const char *repo_path, int repo_read_only } __dead static void +usage_init(void) +{ + fprintf(stderr, "usage: %s init [-b branch] repository-path\n", + getprogname()); + exit(1); +} + +static const struct got_error * +cmd_init(int argc, char *argv[]) +{ + const struct got_error *error = NULL; + const char *head_name = NULL; + char *repo_path = NULL; + int ch; + + while ((ch = getopt(argc, argv, "b:")) != -1) { + switch (ch) { + case 'b': + head_name = optarg; + break; + default: + usage_init(); + /* NOTREACHED */ + } + } + + argc -= optind; + argv += optind; + +#ifndef PROFILE + if (pledge("stdio rpath wpath cpath unveil", NULL) == -1) + err(1, "pledge"); +#endif + if (argc != 1) + usage_init(); + + repo_path = strdup(argv[0]); + if (repo_path == NULL) + return got_error_from_errno("strdup"); + + got_path_strip_trailing_slashes(repo_path); + + error = got_path_mkdir(repo_path); + if (error && + !(error->code == GOT_ERR_ERRNO && errno == EEXIST)) + goto done; + + error = apply_unveil(repo_path, 0, NULL); + if (error) + goto done; + + error = got_repo_init(repo_path, head_name); +done: + free(repo_path); + return error; +} + +__dead static void usage_import(void) { fprintf(stderr, "usage: %s import [-b branch] [-I pattern] [-m message] " blob - dde785d1cee7ca7d6591b4aeae5dc65472294bc7 blob + 00bb07ed7939d88c75f1fb6e94a7b77a86d50730 --- gotadmin/gotadmin.1 +++ gotadmin/gotadmin.1 @@ -59,11 +59,28 @@ Create a new empty repository at the specified .Pp After .Cm gotadmin init , -the -.Cm got import -command must be used to populate the empty repository before +the new repository must be populated before .Cm got checkout can be used. +The +.Cm got import +command can be used to populate the new repository with data from +a local directory. +Alternatively, on a server running +.Xr gotd 8 , +the new repository can be made available to +.Xr got 1 +or +.Xr git 1 +clients by adding the repository to +.Xr gotd.conf 5 +and restarting +.Xr gotd 8 . +Clients may then clone the new repository from the server, populate the cloned +repository, and then populate the new repository on the server via +.Cm got send +or +.Cm git push . .Pp The options for .Cm gotadmin init @@ -75,6 +92,11 @@ Make the repository's HEAD reference point to the spec instead of the default branch .Dq main . .El +.Pp +The +.Cm gotadmin init +command is equivalent to +.Cm got init . .It Cm info Op Fl r Ar repository-path Display information about a repository. This includes some configuration settings from blob - 3deea57b8d4424f745a81ebe3900dbf4632bd8d7 blob + 641a80e0f4d3a3e6c42194d00008d26feca19ae0 --- regress/cmdline/import.sh +++ regress/cmdline/import.sh @@ -21,7 +21,7 @@ test_import_basic() { local testroot=`mktemp -d \ "$GOT_TEST_ROOT/got-test-$testname-XXXXXXXXXX"` - gotadmin init $testroot/repo + got init $testroot/repo mkdir $testroot/tree make_test_tree $testroot/tree @@ -372,7 +372,7 @@ test_import_ignores() { local testroot=`mktemp -d \ "$GOT_TEST_ROOT/got-test-$testname-XXXXXXXXXX"` - gotadmin init $testroot/repo + got init $testroot/repo mkdir $testroot/tree make_test_tree $testroot/tree blob - 2f9468695f6cf968b15297cfe13f3ecee0544e73 blob + d8eb96bab4f0e3966cb1fb48167fcf1be88c38f7 --- regress/cmdline/log.sh +++ regress/cmdline/log.sh @@ -670,7 +670,7 @@ test_log_in_worktree_different_repo() { git_commit $testroot/repo -m "adding the test tree" local head_commit=`git_show_head $testroot/repo` - gotadmin init $testroot/other-repo + got init $testroot/other-repo mkdir -p $testroot/tree make_test_tree $testroot/tree got import -mm -b foo -r $testroot/other-repo $testroot/tree >/dev/null