Merge branch 'sb/worktree-remove-opt-force'
authorJunio C Hamano <gitster@pobox.com>
Tue, 8 May 2018 06:59:24 +0000 (15:59 +0900)
committerJunio C Hamano <gitster@pobox.com>
Tue, 8 May 2018 06:59:24 +0000 (15:59 +0900)
"git worktree remove" learned that "-f" is a shorthand for
"--force" option, just like for "git worktree add".

* sb/worktree-remove-opt-force:
worktree: accept -f as short for --force for removal

1  2 
Documentation/git-worktree.txt
builtin/worktree.c
index 2755ca90e3a457538a2f7a016fbe944b7e51b88b,99b713c8490d2a4defaacf292ef8348a1e83af9d..9920d9c06ed213ad12c89050742b2da949303445
@@@ -14,7 -14,7 +14,7 @@@ SYNOPSI
  'git worktree lock' [--reason <string>] <worktree>
  'git worktree move' <worktree> <new-path>
  'git worktree prune' [-n] [-v] [--expire <expire>]
- 'git worktree remove' [--force] <worktree>
+ 'git worktree remove' [-f] <worktree>
  'git worktree unlock' <worktree>
  
  DESCRIPTION
@@@ -27,12 -27,11 +27,12 @@@ out more than one branch at a time.  Wi
  tree is associated with the repository.  This new working tree is called a
  "linked working tree" as opposed to the "main working tree" prepared by "git
  init" or "git clone".  A repository has one main working tree (if it's not a
 -bare repository) and zero or more linked working trees.
 +bare repository) and zero or more linked working trees. When you are done
 +with a linked working tree, remove it with `git worktree remove`.
  
 -When you are done with a linked working tree you can simply delete it.
 -The working tree's administrative files in the repository (see
 -"DETAILS" below) will eventually be removed automatically (see
 +If a working tree is deleted without using `git worktree remove`, then
 +its associated administrative files, which reside in the repository
 +(see "DETAILS" below), will eventually be removed automatically (see
  `gc.worktreePruneExpire` in linkgit:git-config[1]), or you can run
  `git worktree prune` in the main or any linked working tree to
  clean up any stale administrative files.
@@@ -107,7 -106,7 +107,7 @@@ OPTION
        By default, `add` refuses to create a new working tree when
        `<commit-ish>` is a branch name and is already checked out by
        another working tree and `remove` refuses to remove an unclean
 -      working tree. This option overrides that safeguard.
 +      working tree. This option overrides these safeguards.
  
  -b <new-branch>::
  -B <new-branch>::
@@@ -233,7 -232,7 +233,7 @@@ The worktree list command has two outpu
  details on a single line with columns.  For example:
  
  ------------
 -S git worktree list
 +$ git worktree list
  /path/to/bare-source            (bare)
  /path/to/linked-worktree        abcd1234 [master]
  /path/to/other-linked-worktree  1234abc  (detached HEAD)
@@@ -248,7 -247,7 +248,7 @@@ if the value is true.  An empty line in
  example:
  
  ------------
 -S git worktree list --porcelain
 +$ git worktree list --porcelain
  worktree /path/to/bare-source
  bare
  
@@@ -279,7 -278,8 +279,7 @@@ $ pushd ../tem
  # ... hack hack hack ...
  $ git commit -a -m 'emergency fix for boss'
  $ popd
 -$ rm -rf ../temp
 -$ git worktree prune
 +$ git worktree remove ../temp
  ------------
  
  BUGS
diff --combined builtin/worktree.c
index 40a438ed6ce802e0745495ba611e49c23e2eefce,dba460f8130c0d9835a32b5e259694e58b6f2df8..30647b30c5337e23c70720558a5ab96e9a8d68fd
@@@ -101,9 -101,16 +101,9 @@@ static int prune_worktree(const char *i
        }
        path[len] = '\0';
        if (!file_exists(path)) {
 -              struct stat st_link;
                free(path);
 -              /*
 -               * the repo is moved manually and has not been
 -               * accessed since?
 -               */
 -              if (!stat(git_path("worktrees/%s/link", id), &st_link) &&
 -                  st_link.st_nlink > 1)
 -                      return 0;
 -              if (st.st_mtime <= expire) {
 +              if (stat(git_path("worktrees/%s/index", id), &st) ||
 +                  st.st_mtime <= expire) {
                        strbuf_addf(reason, _("Removing worktrees/%s: gitdir file points to non-existent location"), id);
                        return 1;
                } else {
@@@ -495,7 -502,7 +495,7 @@@ static void show_worktree(struct worktr
                strbuf_addstr(&sb, "(bare)");
        else {
                strbuf_addf(&sb, "%-*s ", abbrev_len,
 -                              find_unique_abbrev(wt->head_oid.hash, DEFAULT_ABBREV));
 +                              find_unique_abbrev(&wt->head_oid, DEFAULT_ABBREV));
                if (wt->is_detached)
                        strbuf_addstr(&sb, "(detached HEAD)");
                else if (wt->head_ref) {
@@@ -520,7 -527,7 +520,7 @@@ static void measure_widths(struct workt
  
                if (path_len > *maxlen)
                        *maxlen = path_len;
 -              sha1_len = strlen(find_unique_abbrev(wt[i]->head_oid.hash, *abbrev));
 +              sha1_len = strlen(find_unique_abbrev(&wt[i]->head_oid, *abbrev));
                if (sha1_len > *abbrev)
                        *abbrev = sha1_len;
        }
@@@ -783,8 -790,9 +783,9 @@@ static int remove_worktree(int ac, cons
  {
        int force = 0;
        struct option options[] = {
-               OPT_BOOL(0, "force", &force,
-                        N_("force removing even if the worktree is dirty")),
+               OPT__FORCE(&force,
+                        N_("force removing even if the worktree is dirty"),
+                        PARSE_OPT_NOCOMPLETE),
                OPT_END()
        };
        struct worktree **worktrees, *wt;