Commit b339dd48 authored by ian@well-typed.com's avatar ian@well-typed.com
Browse files

Change how sync-all handles directory changes

We now remember the current working directory right at the start,
and change back to it after we've finished working in a subdirectory.

This should fix a problem some people have been seeing, where
sync-all thinks that they have an out-of-date time library because
its working directory has gone wrong somehow.
parent 713c514d
...@@ -5,6 +5,8 @@ use Cwd; ...@@ -5,6 +5,8 @@ use Cwd;
$| = 1; # autoflush stdout after each print, to avoid output after die $| = 1; # autoflush stdout after each print, to avoid output after die
my $initial_working_directory;
my $defaultrepo; my $defaultrepo;
my @packages; my @packages;
my $verbose = 2; my $verbose = 2;
...@@ -143,13 +145,11 @@ sub gitNewWorkdir { ...@@ -143,13 +145,11 @@ sub gitNewWorkdir {
my $dir = shift; my $dir = shift;
my $target = shift; my $target = shift;
my $target_dir = "$target/$dir"; my $target_dir = "$target/$dir";
my $pwd;
if ($dir eq '.') { if ($dir eq '.') {
message "== running git-new-workdir . $target_dir @_"; message "== running git-new-workdir . $target_dir @_";
} else { } else {
message "== $dir: running git-new-workdir . $target_dir @_"; message "== $dir: running git-new-workdir . $target_dir @_";
$pwd = getcwd();
chdir($dir); chdir($dir);
} }
...@@ -158,20 +158,18 @@ sub gitNewWorkdir { ...@@ -158,20 +158,18 @@ sub gitNewWorkdir {
or die "git-new-workdir failed: $?"; or die "git-new-workdir failed: $?";
if ($dir ne '.') { if ($dir ne '.') {
chdir($pwd); chdir($initial_working_directory);
} }
} }
sub scm { sub scm {
my $dir = shift; my $dir = shift;
my $scm = shift; my $scm = shift;
my $pwd;
if ($dir eq '.') { if ($dir eq '.') {
message "== running $scm @_"; message "== running $scm @_";
} else { } else {
message "== $dir: running $scm @_"; message "== $dir: running $scm @_";
$pwd = getcwd();
chdir($dir); chdir($dir);
} }
...@@ -180,7 +178,7 @@ sub scm { ...@@ -180,7 +178,7 @@ sub scm {
or die "$scm failed: $?"; or die "$scm failed: $?";
if ($dir ne '.') { if ($dir ne '.') {
chdir($pwd); chdir($initial_working_directory);
} }
} }
...@@ -196,9 +194,7 @@ sub scmall { ...@@ -196,9 +194,7 @@ sub scmall {
my $subcommand; my $subcommand;
my $path; my $path;
my $wd_before = getcwd;
my $pwd;
my @args; my @args;
my $started; my $started;
...@@ -796,9 +792,14 @@ sub main { ...@@ -796,9 +792,14 @@ sub main {
} }
} }
BEGIN {
$initial_working_directory = getcwd();
}
END { END {
my $ec = $?; my $ec = $?;
my $pwd = getcwd();
chdir($initial_working_directory);
message "== Checking for old haddock repo"; message "== Checking for old haddock repo";
if (-d "utils/haddock/.git") { if (-d "utils/haddock/.git") {
...@@ -815,7 +816,7 @@ Please remove it (e.g. "rm -r utils/haddock"), and then run ...@@ -815,7 +816,7 @@ Please remove it (e.g. "rm -r utils/haddock"), and then run
============================ ============================
EOF EOF
} }
chdir($pwd); chdir($initial_working_directory);
} }
message "== Checking for old binary repo"; message "== Checking for old binary repo";
...@@ -833,7 +834,7 @@ Please remove it (e.g. "rm -r libraries/binary"), and then run ...@@ -833,7 +834,7 @@ Please remove it (e.g. "rm -r libraries/binary"), and then run
============================ ============================
EOF EOF
} }
chdir($pwd); chdir($initial_working_directory);
} }
message "== Checking for old mtl repo"; message "== Checking for old mtl repo";
...@@ -851,7 +852,7 @@ Please remove it (e.g. "rm -r libraries/mtl"), and then run ...@@ -851,7 +852,7 @@ Please remove it (e.g. "rm -r libraries/mtl"), and then run
============================ ============================
EOF EOF
} }
chdir($pwd); chdir($initial_working_directory);
} }
message "== Checking for old Cabal repo"; message "== Checking for old Cabal repo";
...@@ -869,7 +870,7 @@ Please remove it (e.g. "rm -r libraries/Cabal"), and then run ...@@ -869,7 +870,7 @@ Please remove it (e.g. "rm -r libraries/Cabal"), and then run
============================ ============================
EOF EOF
} }
chdir($pwd); chdir($initial_working_directory);
} }
message "== Checking for old time from tarball"; message "== Checking for old time from tarball";
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment