@@ -304,8 +304,6 @@ int write_archive_entries(struct archiver_args *args,
304304 write_archive_entry_fn_t write_entry )
305305{
306306 struct archiver_context context ;
307- struct unpack_trees_options opts ;
308- struct tree_desc t ;
309307 int err ;
310308 struct strbuf path_in_archive = STRBUF_INIT ;
311309 struct strbuf content = STRBUF_INIT ;
@@ -331,23 +329,6 @@ int write_archive_entries(struct archiver_args *args,
331329 context .args = args ;
332330 context .write_entry = write_entry ;
333331
334- /*
335- * Setup index and instruct attr to read index only
336- */
337- if (!args -> worktree_attributes ) {
338- memset (& opts , 0 , sizeof (opts ));
339- opts .index_only = 1 ;
340- opts .head_idx = -1 ;
341- opts .src_index = args -> repo -> index ;
342- opts .dst_index = args -> repo -> index ;
343- opts .fn = oneway_merge ;
344- init_tree_desc (& t , & args -> tree -> object .oid ,
345- args -> tree -> buffer , args -> tree -> size );
346- if (unpack_trees (1 , & t , & opts ))
347- return -1 ;
348- git_attr_set_direction (GIT_ATTR_INDEX );
349- }
350-
351332 err = read_tree (args -> repo , args -> tree ,
352333 & args -> pathspec ,
353334 queue_or_write_archive_entry ,
@@ -540,6 +521,26 @@ static void parse_treeish_arg(const char **argv,
540521 if (!tree )
541522 die (_ ("not a tree object: %s" ), oid_to_hex (& oid ));
542523
524+ /*
525+ * Setup index and instruct attr to read index only
526+ */
527+ if (!ar_args -> worktree_attributes ) {
528+ struct unpack_trees_options opts ;
529+ struct tree_desc t ;
530+
531+ memset (& opts , 0 , sizeof (opts ));
532+ opts .index_only = 1 ;
533+ opts .head_idx = -1 ;
534+ opts .src_index = ar_args -> repo -> index ;
535+ opts .dst_index = ar_args -> repo -> index ;
536+ opts .fn = oneway_merge ;
537+ init_tree_desc (& t , & tree -> object .oid , tree -> buffer , tree -> size );
538+ if (unpack_trees (1 , & t , & opts ))
539+ die (_ ("unable to checkout working tree" ));
540+
541+ git_attr_set_direction (GIT_ATTR_INDEX );
542+ }
543+
543544 ar_args -> refname = ref ;
544545 ar_args -> tree = tree ;
545546 ar_args -> commit_oid = commit_oid ;
0 commit comments