~ubuntu-branches/ubuntu/intrepid/git-core/intrepid-security

« back to all changes in this revision

Viewing changes to builtin-init-db.c

  • Committer: Package Import Robot
  • Author(s): Gerrit Pape
  • Date: 2007-10-04 08:27:01 UTC
  • mfrom: (1.1.23)
  • Revision ID: package-import@ubuntu.com-20071004082701-rsd058ontoqz4i30
Tags: 1:1.5.3.4-1
new upstream point release (closes: #445188).

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
#include "builtin.h"
8
8
 
9
9
#ifndef DEFAULT_GIT_TEMPLATE_DIR
10
 
#define DEFAULT_GIT_TEMPLATE_DIR "/usr/share/git-core/templates/"
 
10
#define DEFAULT_GIT_TEMPLATE_DIR "/usr/share/git-core/templates"
11
11
#endif
12
12
 
13
13
#ifdef NO_TRUSTABLE_FILEMODE
40
40
                return fdo;
41
41
        }
42
42
        status = copy_fd(fdi, fdo);
43
 
        close(fdo);
 
43
        if (close(fdo) != 0)
 
44
                return error("%s: write error: %s", dst, strerror(errno));
44
45
 
45
46
        if (!status && adjust_shared_perm(dst))
46
47
                return -1;
252
253
        }
253
254
        git_config_set("core.filemode", filemode ? "true" : "false");
254
255
 
255
 
        if (is_bare_repository()) {
 
256
        if (is_bare_repository())
256
257
                git_config_set("core.bare", "true");
257
 
        }
258
258
        else {
 
259
                const char *work_tree = get_git_work_tree();
259
260
                git_config_set("core.bare", "false");
260
261
                /* allow template config file to override the default */
261
262
                if (log_all_ref_updates == -1)
262
263
                    git_config_set("core.logallrefupdates", "true");
263
 
        }
 
264
                if (work_tree != git_work_tree_cfg)
 
265
                        git_config_set("core.worktree", work_tree);
 
266
        }
 
267
 
 
268
        /* Check if symlink is supported in the work tree */
 
269
        if (!reinit) {
 
270
                path[len] = 0;
 
271
                strcpy(path + len, "tXXXXXX");
 
272
                if (!close(xmkstemp(path)) &&
 
273
                    !unlink(path) &&
 
274
                    !symlink("testing", path) &&
 
275
                    !lstat(path, &st1) &&
 
276
                    S_ISLNK(st1.st_mode))
 
277
                        unlink(path); /* good */
 
278
                else
 
279
                        git_config_set("core.symlinks", "false");
 
280
        }
 
281
 
264
282
        return reinit;
265
283
}
266
284
 
 
285
static void guess_repository_type(const char *git_dir)
 
286
{
 
287
        char cwd[PATH_MAX];
 
288
        const char *slash;
 
289
 
 
290
        if (0 <= is_bare_repository_cfg)
 
291
                return;
 
292
        if (!git_dir)
 
293
                return;
 
294
 
 
295
        /*
 
296
         * "GIT_DIR=. git init" is always bare.
 
297
         * "GIT_DIR=`pwd` git init" too.
 
298
         */
 
299
        if (!strcmp(".", git_dir))
 
300
                goto force_bare;
 
301
        if (!getcwd(cwd, sizeof(cwd)))
 
302
                die("cannot tell cwd");
 
303
        if (!strcmp(git_dir, cwd))
 
304
                goto force_bare;
 
305
        /*
 
306
         * "GIT_DIR=.git or GIT_DIR=something/.git is usually not.
 
307
         */
 
308
        if (!strcmp(git_dir, ".git"))
 
309
                return;
 
310
        slash = strrchr(git_dir, '/');
 
311
        if (slash && !strcmp(slash, "/.git"))
 
312
                return;
 
313
 
 
314
        /*
 
315
         * Otherwise it is often bare.  At this point
 
316
         * we are just guessing.
 
317
         */
 
318
 force_bare:
 
319
        is_bare_repository_cfg = 1;
 
320
        return;
 
321
}
 
322
 
267
323
static const char init_db_usage[] =
268
 
"git-init [--template=<template-directory>] [--shared]";
 
324
"git-init [-q | --quiet] [--template=<template-directory>] [--shared]";
269
325
 
270
326
/*
271
327
 * If you want to, you can share the DB area with any number of branches.
280
336
        const char *template_dir = NULL;
281
337
        char *path;
282
338
        int len, i, reinit;
 
339
        int quiet = 0;
283
340
 
284
341
        for (i = 1; i < argc; i++, argv++) {
285
342
                const char *arg = argv[1];
289
346
                        shared_repository = PERM_GROUP;
290
347
                else if (!prefixcmp(arg, "--shared="))
291
348
                        shared_repository = git_config_perm("arg", arg+9);
 
349
                else if (!strcmp(arg, "-q") || !strcmp(arg, "--quiet"))
 
350
                        quiet = 1;
292
351
                else
293
352
                        usage(init_db_usage);
294
353
        }
295
354
 
296
355
        /*
 
356
         * GIT_WORK_TREE makes sense only in conjunction with GIT_DIR
 
357
         * without --bare.  Catch the error early.
 
358
         */
 
359
        git_dir = getenv(GIT_DIR_ENVIRONMENT);
 
360
        if ((!git_dir || is_bare_repository_cfg == 1)
 
361
            && getenv(GIT_WORK_TREE_ENVIRONMENT))
 
362
                die("%s (or --work-tree=<directory>) not allowed without "
 
363
                    "specifying %s (or --git-dir=<directory>)",
 
364
                    GIT_WORK_TREE_ENVIRONMENT,
 
365
                    GIT_DIR_ENVIRONMENT);
 
366
 
 
367
        guess_repository_type(git_dir);
 
368
 
 
369
        if (is_bare_repository_cfg <= 0) {
 
370
                git_work_tree_cfg = xcalloc(PATH_MAX, 1);
 
371
                if (!getcwd(git_work_tree_cfg, PATH_MAX))
 
372
                        die ("Cannot access current working directory.");
 
373
                if (access(get_git_work_tree(), X_OK))
 
374
                        die ("Cannot access work tree '%s'",
 
375
                             get_git_work_tree());
 
376
        }
 
377
 
 
378
        /*
297
379
         * Set up the default .git directory contents
298
380
         */
299
381
        git_dir = getenv(GIT_DIR_ENVIRONMENT);
335
417
                git_config_set("receive.denyNonFastforwards", "true");
336
418
        }
337
419
 
338
 
        printf("%s%s Git repository in %s/\n",
339
 
                reinit ? "Reinitialized existing" : "Initialized empty",
340
 
                shared_repository ? " shared" : "",
341
 
                git_dir);
 
420
        if (!quiet)
 
421
                printf("%s%s Git repository in %s/\n",
 
422
                       reinit ? "Reinitialized existing" : "Initialized empty",
 
423
                       shared_repository ? " shared" : "",
 
424
                       git_dir);
342
425
 
343
426
        return 0;
344
427
}