summaryrefslogtreecommitdiff
path: root/git-cvsimport-script
diff options
context:
space:
mode:
authorMatthias Urlichs <smurf@kiste.(none)>2005-06-28 19:08:15 (GMT)
committerMatthias Urlichs <smurf@kiste.(none)>2005-06-28 19:08:15 (GMT)
commit465416694a98a8f071abf6290c9a2a48d9789a98 (patch)
tree4899c030ebd678228d19dc78e1151d42c2d2fb47 /git-cvsimport-script
parentf65ae603db8ffc36e25cc835eeffcfe4909c3148 (diff)
downloadgit-465416694a98a8f071abf6290c9a2a48d9789a98.zip
git-465416694a98a8f071abf6290c9a2a48d9789a98.tar.gz
git-465416694a98a8f071abf6290c9a2a48d9789a98.tar.bz2
Rollbak to the original branch after importing
Diffstat (limited to 'git-cvsimport-script')
-rwxr-xr-xgit-cvsimport-script29
1 files changed, 25 insertions, 4 deletions
diff --git a/git-cvsimport-script b/git-cvsimport-script
index 58ded8a..0d205c5 100755
--- a/git-cvsimport-script
+++ b/git-cvsimport-script
@@ -323,6 +323,7 @@ sub getwd() {
chdir($git_tree);
my $last_branch = "";
+my $orig_branch = "";
my %branch_date;
my $git_dir = $ENV{"GIT_DIR"} || ".git";
@@ -335,9 +336,14 @@ unless(-d $git_dir) {
die "Cannot init an empty tree: $?\n" if $?;
$last_branch = $opt_o;
+ $orig_branch = "";
} else {
$last_branch = basename(readlink("$git_dir/HEAD"));
- die "Cannot read the last branch name: $!\n" unless $last_branch;
+ unless($last_branch) {
+ warn "Cannot read the last branch name: $! -- assuming 'master'\n";
+ $last_branch = "master";
+ }
+ $orig_branch = $last_branch;
# Get the last import timestamps
opendir(D,"$git_dir/refs/heads");
@@ -558,8 +564,8 @@ while(<CVS>) {
}
if(($ancestor || $branch) ne $last_branch) {
print "Switching from $last_branch to $branch\n" if $opt_v;
- system("git-read-tree -m -u $last_branch $branch");
- die "read-tree $branch failed at $branch: $?\n" if $?;
+ system("git-read-tree","-m","-u","$last_branch","$branch");
+ die "read-tree failed: $?\n" if $?;
}
if($branch ne $last_branch) {
unlink("$git_dir/HEAD");
@@ -605,4 +611,19 @@ while(<CVS>) {
}
&$commit() if $branch and $state != 11;
-print "DONE\n" if $opt_v;
+# Now switch back to the branch we were in before all of this happened
+if($orig_branch) {
+ print "DONE; switching back to $orig_branch\n" if $opt_v;
+} else {
+ $orig_branch = "master";
+ print "DONE; creating $orig_branch branch\n" if $opt_v;
+ system("cp","$git_dir/refs/heads/$opt_o","$git_dir/refs/heads/master")
+ unless -f "$git_dir/refs/heads/master";
+}
+
+system("git-read-tree","-m","-u","$last_branch","$orig_branch");
+die "read-tree failed: $?\n" if $?;
+
+unlink("$git_dir/HEAD");
+symlink("refs/heads/$orig_branch","$git_dir/HEAD");
+