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

Re: git checkout under 1.7.6 does not properly list untracked files and aborts

From
Joshua Jensen <jjensen@workspacewhiz.com>
Date
Sep 19, 2011, 20:06 UTC
Message-ID
<4E77A0C6.1060703@workspacewhiz.com>
In-Reply-To
<4E779BA4.8070109@workspacewhiz.com>
----- Original Message -----
From: Joshua Jensen
Date: 9/19/2011 1:44 PM
Show 35 quoted lines
> ----- Original Message -----
> From: Joshua Jensen
> Date: 9/9/2011 2:04 PM
>> This may be an msysGit 1.7.6 issue, as that is what I am using.  It 
>> also occurs in msysGit 1.7.5, but I am almost certain it did not 
>> happen in msysGit 1.7.2.
>>
>> Given an untracked file in the working directory that has been added 
>> to an alternate branch, when switching to that alternate branch, 'git 
>> checkout' exits with an error code but does not print anything to the 
>> console.  It should print an untracked file error.
>>
>> I have been trying to track this down in code.  The point where the 
>> error messages are printed, display_error_msgs, is never hit.
> Okay, so I've tracked this down, but I am unsure what the correct fix is.
>
> In unpack-trees.c's unpack_trees() function, there are some lines that 
> read:
>
>     if (ce->ce_flags & CE_ADDED &&
>         verify_absent(ce, ERROR_WOULD_LOSE_UNTRACKED_OVERWRITTEN, o))
>             return -1;
>
> If the 'return -1' is changed to 'goto return_failed', then a proper 
> error message appears:
>
>     error: The following untracked working tree files would be 
> overwritten by checkout:
>         one/file/listed/here.txt
>     Please move or remove them before you can switch branches.
>     Aborting
>
> The thing is, there are multiple files that would be overwritten by 
> checkout, and I believe an older version of Git showed me the entire 
> list before aborting.

While probably not correct, the following patch collects all files that would be overwritten and logs them to the output:

---
  unpack-trees.c |   11 +++++++----
  1 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/unpack-trees.c b/unpack-trees.c
index cc616c3..e1f7263 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -993,7 +993,7 @@ static int verify_absent(struct cache_entry *, enum 
unpack_trees_error_types, st
   */
  int unpack_trees(unsigned len, struct tree_desc *t, struct 
unpack_trees_options *o)
  {
-    int i, ret;
+    int i, ret = 0;
      static struct cache_entry *dfc;
      struct exclude_list el;

@@ -1100,9 +1100,10 @@ int unpack_trees(unsigned len, struct tree_desc 
*t, struct unpack_trees_options
               * Do the real check now because we have had
               * correct CE_NEW_SKIP_WORKTREE
               */
-            if (ce->ce_flags & CE_ADDED &&
-                verify_absent(ce, 
ERROR_WOULD_LOSE_UNTRACKED_OVERWRITTEN, o))
-                    return -1;
+            if (ce->ce_flags & CE_ADDED) {
+                int result = verify_absent(ce, 
ERROR_WOULD_LOSE_UNTRACKED_OVERWRITTEN, o);
+                ret = min(ret, result);
+            }

              if (apply_sparse_checkout(ce, o)) {
                  ret = -1;
@@ -1112,6 +1113,8 @@ int unpack_trees(unsigned len, struct tree_desc 
*t, struct unpack_trees_options
                  empty_worktree = 0;

          }
+        if (ret == -1)
+            goto return_failed;
          if (o->result.cache_nr && empty_worktree) {
              /* dubious---why should this fail??? */
              ret = unpack_failed(o, "Sparse checkout leaves no entry on 
working directory");
-- 
1.7.6.msysgit.1
Previous: Joshua JensenNext: Michael J Gruber
Message 3 of 23 in “git checkout under 1.7.6 does not properly list untracked files and aborts”
  1. Joshua JensenSep 9, 2011
  2. Joshua JensenSep 19, 2011
  3. Joshua JensenSep 19, 2011
  4. Michael J GruberSep 20, 2011
  5. Joshua JensenSep 20, 2011
  6. Michael J GruberSep 21, 2011
  7. 0/3 read-tree cleanupsMichael J Gruber, Sep 21, 2011
  8. Michael J GruberSep 21, 2011
  9. Junio C HamanoSep 21, 2011
  10. 1/3 unpack-trees: print "Aborting" to stderrMichael J Gruber, Sep 21, 2011
  11. Junio C HamanoSep 21, 2011
  12. Junio C HamanoSep 21, 2011
  13. Michael J GruberSep 22, 2011
  14. 2/3 git-read-tree.txt: language and typography fixesMichael J Gruber, Sep 21, 2011
  15. 3/3 git-read-tree.txt: correct sparse-checkout and skip-worktree descriptionMichael J Gruber, Sep 21, 2011
  16. Nguyen Thai Ngoc DuySep 21, 2011
  17. Michael J GruberSep 21, 2011
  18. Nguyen Thai Ngoc DuySep 21, 2011
  19. Michael J GruberSep 21, 2011
  20. Nguyen Thai Ngoc DuySep 21, 2011
  21. Michael J GruberSep 21, 2011
  22. Nguyen Thai Ngoc DuySep 21, 2011
  23. Nguyen Thai Ngoc DuySep 21, 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.