+ foreach my $dir ("", ".git") {
+ if (!mkdir("$working/$dir")) {
+ error("Unable to create $working/$dir: $!");
+ }
+ }
+
+ # Hooks are deliberately not included: we will commit to the temporary
+ # branch that is used in the temporary working tree, and we don't want
+ # to run the post-commit hook there.
+ #
+ # logs/refs is not included because we don't use the reflog.
+ # remotes, rr-cache, svn are similarly excluded.
+ foreach my $link ("config", "refs", "objects", "info", "packed-refs") {
+ if (!symlink("../../$link", "$working/.git/$link")) {
+ error("Unable to create symlink $working/.git/$link: $!");
+ }
+ }
+
+ open (my $out, '>', "$working/.git/HEAD") or
+ error("failed to write $working.git/HEAD: $!");
+ print $out "ref: refs/heads/$branch\n" or
+ error("failed to write $working.git/HEAD: $!");
+ close $out or
+ error("failed to write $working.git/HEAD: $!");
+ return $working;