git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] do not overwrite untracked symlinks

From
Clemens Buchacher <drizzd@aon.at>
Date
Feb 20, 2011, 12:13 UTC
Message-ID
<20110220121343.GA21514@localhost>
In-Reply-To
<20110205183351.GA25717@localhost>

Git traditionally overwrites untracked symlinks silently. This will generally not cause massive data loss, but it is inconsistent with the behavior for regular files, which are not silently overwritten.

With this change, git refuses to overwrite untracked symlinks by default. If the user really wants to overwrite the untracked symlink, he has git-clean and git-checkout -f at his disposal.

Signed-off-by: Clemens Buchacher <drizzd@aon.at>
---

I checked and there are no undesireable side-effects. One test had to be modified slightly because it does overwrite an untracked symlink.

 symlinks.c                      |    2 +-
 t/t6035-merge-dir-to-symlink.sh |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/symlinks.c b/symlinks.c
index 3cacebd..034943b 100644
--- a/symlinks.c
+++ b/symlinks.c
@@ -223,7 +223,7 @@ int check_leading_path(const char *name, int len)
 	int flags;
 	int match_len = lstat_cache_matchlen(cache, name, len, &flags,
 			   FL_SYMLINK|FL_NOENT|FL_DIR, USE_ONLY_LSTAT);
-	if (flags & (FL_SYMLINK|FL_NOENT))
+	if (flags & FL_NOENT)
 		return 0;
 	else if (flags & FL_DIR)
 		return -1;
diff --git a/t/t6035-merge-dir-to-symlink.sh b/t/t6035-merge-dir-to-symlink.sh
index 92e02d5..1de285b 100755
--- a/t/t6035-merge-dir-to-symlink.sh
+++ b/t/t6035-merge-dir-to-symlink.sh
@@ -22,7 +22,7 @@ test_expect_success SYMLINKS 'keep a/b-2/c/d across checkout' '
 	git reset --hard master &&
 	git rm --cached a/b &&
 	git commit -m "untracked symlink remains" &&
-	 git checkout start^0 &&
+	 git checkout -f start^0 &&
 	 test -f a/b-2/c/d
 '
 
-- 
1.7.3.1.105.g84915
Previous: Clemens BuchacherNext: Junio C Hamano
Message 8 of 14 in “untracked symlinks are less precious than untracked files?”
  1. Johannes SixtFeb 2, 2011
  2. Junio C HamanoFeb 2, 2011
  3. Johannes SixtFeb 2, 2011
  4. Demonstrate breakage: checkout overwrites untracked symlink with directoryJohannes Sixt, Feb 5, 2011
  5. Clemens BuchacherFeb 5, 2011
  6. Junio C HamanoFeb 9, 2011
  7. Clemens BuchacherFeb 10, 2011
  8. do not overwrite untracked symlinksClemens Buchacher, Feb 20, 2011
  9. Junio C HamanoFeb 21, 2011
  10. Clemens BuchacherFeb 21, 2011
  11. Junio C HamanoFeb 22, 2011
  12. Clemens BuchacherFeb 22, 2011
  13. Junio C HamanoFeb 22, 2011
  14. Johannes SixtFeb 15, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.