Skip to content

Commit 4f4ad3d

Browse files
martinvonzgitster
authored andcommitted
reset: don't allow "git reset -- $pathspec" in bare repo
Running e.g. "git reset ." in a bare repo results in an index file being created from the HEAD commit. The differences compared to the index are then printed as usual, but since there is no worktree, it will appear as if all files are deleted. For example, in a bare clone of git.git: Unstaged changes after reset: D .gitattributes D .gitignore D .mailmap ... This happens because the check for is_bare_repository() happens after we branch off into read_from_tree() to reset with paths. Fix by moving the branching point after the check. Signed-off-by: Martin von Zweigbergk <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 18648e8 commit 4f4ad3d

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

builtin/reset.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,6 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
295295
else if (reset_type != NONE)
296296
die(_("Cannot do %s reset with paths."),
297297
_(reset_type_names[reset_type]));
298-
return read_from_tree(pathspec, sha1,
299-
quiet ? REFRESH_QUIET : REFRESH_IN_PORCELAIN);
300298
}
301299
if (reset_type == NONE)
302300
reset_type = MIXED; /* by default */
@@ -308,6 +306,10 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
308306
die(_("%s reset is not allowed in a bare repository"),
309307
_(reset_type_names[reset_type]));
310308

309+
if (pathspec)
310+
return read_from_tree(pathspec, sha1,
311+
quiet ? REFRESH_QUIET : REFRESH_IN_PORCELAIN);
312+
311313
/* Soft reset does not touch the index file nor the working tree
312314
* at all, but requires them in a good order. Other resets reset
313315
* the index file to the tree object we are switching to. */

0 commit comments

Comments
 (0)