Created
January 5, 2016 14:16
-
-
Save seudut/f4d74e1bc026e271cd6e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl -w | |
use strict; | |
# | |
my $commit = ""; | |
my $cc = $ARGV[0]; | |
my $up_branch = "up_branch"; | |
chdir "./adaptation_resilience"; | |
my @commits = reverse split /\n/, `git log --first-parent --oneline origin/master | awk '{print \$1}'`; | |
##### | |
# | |
my $ll = shift @commits; | |
while ($cc ne $ll){ $ll = shift @commits;} | |
unshift @commits, $ll; | |
####### | |
foreach $commit (@commits) | |
{ | |
my $export_branch = "e88_" . $commit; | |
print "======== commit $commit ==========\n"; | |
## update svn | |
print "======= svn update =========\n"; | |
print `git svn fetch svn`; | |
##!system "git svn fetch svn" or die "fetch"; | |
## reset up_branch | |
!system "git checkout $up_branch" or die "$!"; | |
!system "git reset --hard $commit" or die "$!"; | |
### create import branch | |
!system "git checkout -b $export_branch git-svn" or die " checkout $!"; | |
my $num_commmits = 0; | |
my $msg_commit = " commit ===== $commit ====== "; | |
#### 1. check file mode, if has file that mode change, first commit these since merge cannot merge this automatically; | |
my @files_mode_change = split /\n/, `git diff --summary ..up_branch | grep 'mode change' | awk '{ print \$6}'`; | |
if (@files_mode_change ){ | |
print "======= file mode change ========\n"; | |
system "git checkout up_branch -- $_" foreach @files_mode_change; | |
system "git commit -m '" . " $msg_commit ++++ file mode changes ' "; | |
$num_commmits++; | |
} | |
### 2. check deleted file; and commit first | |
my @files_deleted = split /\n/, `git diff --name-status ..up_branch | grep '^D' | awk '{ print \$2}'`; | |
if (@files_deleted) | |
{ | |
print "========= file deleted ========\n"; | |
system "git rm $_" foreach @files_deleted; | |
system "git commit -m '" . " $msg_commit ++++ deleted files'"; | |
$num_commmits++; | |
} | |
## 3. merge the other changes | |
!system 'git merge --strategy=recursive -X theirs ' . $commit . " -m '" . "$msg_commit'" or die " merge $!"; | |
### 4. merge all commit above into one git commit | |
if ($num_commmits) | |
{ | |
$num_commmits++; | |
system "git reset --soft HEAD~$num_commmits"; | |
system "git commit -m '" . " $msg_commit ++++ file mode change or deleted file === $num_commmits====' "; | |
} | |
### 5. last check before svn commit | |
die "Error: ***** still has diff $! *******" unless (&is_branch_same ($export_branch, $up_branch)); | |
## 6. svn commit | |
print "================= ALL ok ================= svn dcommit ==== $commit ==========\n"; | |
!system "git svn dcommit --no-rebase" or die " dcommit $!"; | |
die "Error: ===== svn not update ====" unless &check_svn_update("git-svn", "up_branch", 3); | |
print "successfully $commit"; | |
###!system "git svn fetch svn" or die " svn fetch "; | |
#### foreach (1..20){ | |
#### print "."; | |
#### sleep 1; | |
#### } | |
#### print "======= svn update =========\n"; | |
#### open UPDATE, "git svn fetch svn |" or die " update $!"; | |
#### while(<UPDATE>) | |
#### { | |
#### print; | |
#### } | |
#### sleep 10; | |
#### | |
#### unless (&is_branch_same ("git-svn", $up_branch)) | |
#### { | |
#### print `git svn fetch svn`; | |
#### } | |
#### | |
####### after svn update, check git-svn with up_branch | |
#### die "Error : still diff $commit $!" unless (&is_branch_same ("git-svn", $up_branch)); | |
#### | |
#### print "successfully $commit"; | |
} | |
## arguments $_[0], $_[1], $[2]; | |
sub check_svn_update () | |
{ | |
print `git svn fetch svn`; | |
return 1 if is_branch_same($_[0], $_[1]); | |
return 0 if($_[2] < 0); | |
sleep 10; | |
&check_svn_update($_[0], $_[1], $_[2]-1); | |
} | |
sub is_branch_same () | |
{ | |
!system "git diff $_[0]..$_[1] --exit-code > /dev/null 2>&1"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment