... | ... |
@@ -66,8 +66,8 @@ sub work_rep_info { |
66 | 66 |
my $info = {}; |
67 | 67 |
$info->{user} = $user; |
68 | 68 |
$info->{project} = $project; |
69 |
- $info->{git_dir} = $self->rep_work_home . "/$user/$project/.git"; |
|
70 |
- $info->{work_tree} = $self->rep_work_home . "/$user/$project"; |
|
69 |
+ $info->{git_dir} = $self->work_rep_home . "/$user/$project/.git"; |
|
70 |
+ $info->{work_tree} = $self->work_rep_home . "/$user/$project"; |
|
71 | 71 |
|
72 | 72 |
return $info; |
73 | 73 |
} |
... | ... |
@@ -19,10 +19,10 @@ has text_exts => sub { ['txt'] }; |
19 | 19 |
has 'time_zone_second'; |
20 | 20 |
has 'app'; |
21 | 21 |
|
22 |
-sub rep_work_current_branch { |
|
23 |
- my ($self, $user, $project) = @_; |
|
22 |
+sub current_branch { |
|
23 |
+ my ($self, $rep_info) = @_; |
|
24 | 24 |
|
25 |
- my @cmd = $self->cmd_work_rep($user, $project, 'rev-parse', '--abbrev-ref', 'HEAD'); |
|
25 |
+ my @cmd = $self->cmd($rep_info, 'rev-parse', '--abbrev-ref', 'HEAD'); |
|
26 | 26 |
|
27 | 27 |
open my $fh, '-|', @cmd |
28 | 28 |
or croak "Can't get current branch: @cmd"; |
... | ... |
@@ -32,6 +32,27 @@ sub rep_work_current_branch { |
32 | 32 |
return $current_branch; |
33 | 33 |
} |
34 | 34 |
|
35 |
+sub branch_names { |
|
36 |
+ my ($self, $rep_info) = @_; |
|
37 |
+ |
|
38 |
+ # Branch names |
|
39 |
+ my @cmd = $self->cmd($rep_info, 'branch'); |
|
40 |
+ open my $fh, '-|', @cmd or return; |
|
41 |
+ |
|
42 |
+ my @lines = <$fh>; |
|
43 |
+ my @branch_names; |
|
44 |
+ for my $branch_name (@lines) { |
|
45 |
+ chomp $branch_name; |
|
46 |
+ $branch_name =~ s/^\*//; |
|
47 |
+ $branch_name =~ s/^\s*//; |
|
48 |
+ $branch_name =~ s/\s*$//; |
|
49 |
+ |
|
50 |
+ push @branch_names, $branch_name; |
|
51 |
+ } |
|
52 |
+ |
|
53 |
+ return \@branch_names; |
|
54 |
+} |
|
55 |
+ |
|
35 | 56 |
sub branch { |
36 | 57 |
my ($self, $rep_info, $branch_name) = @_; |
37 | 58 |
|
... | ... |
@@ -33,6 +33,16 @@ sub create_work_rep { |
33 | 33 |
my @git_clone_cmd = ($self->app->git->bin, 'clone', $rep_git_dir, $work_tree); |
34 | 34 |
Gitprep::Util::run_command(@git_clone_cmd) |
35 | 35 |
or croak "Can't git clone: @git_clone_cmd"; |
36 |
+ |
|
37 |
+ # Create temparary branch |
|
38 |
+ my $gitprep_tmp_branch_name = '__gitprep_tmp_branch__'; |
|
39 |
+ my @git_branch_cmd = $self->app->git->cmd( |
|
40 |
+ $work_rep_info, |
|
41 |
+ 'branch', |
|
42 |
+ $gitprep_tmp_branch_name, |
|
43 |
+ ); |
|
44 |
+ Gitprep::Util::run_command(@git_branch_cmd) |
|
45 |
+ or Carp::croak "Can't execute git branch: @git_branch_cmd"; |
|
36 | 46 |
|
37 | 47 |
# Set user name |
38 | 48 |
my @git_config_user_name = $self->app->git->cmd( |
... | ... |
@@ -65,16 +65,33 @@ |
65 | 65 |
$self->app->manager->create_work_rep($user, $project); |
66 | 66 |
|
67 | 67 |
# Fetch repository |
68 |
- my @git_fetch_cmd = $self->app->git->cmd(app->work_rep_info($user, $project), 'fetch'); |
|
68 |
+ my $work_rep_info = app->work_rep_info($user, $project); |
|
69 |
+ my @git_fetch_cmd = $self->app->git->cmd($work_rep_info, 'fetch'); |
|
69 | 70 |
Gitprep::Util::run_command(@git_fetch_cmd) |
70 | 71 |
or Carp::croak "Can't execute git fetch: @git_fetch_cmd"; |
71 | 72 |
|
72 | 73 |
# git checkout -b origin/$from_rev |
73 |
- # my $gitprep_tmp_branch_name = '__gitprep_tmp_branch_name__'; |
|
74 |
- # my @git_checkout_tmp_branch = $self->app->git->cmd( |
|
75 |
- # app->work_rep_info($user, $project), 'checkout', '-b', $gitprep_tmp_branch_name, "origin/$from_rev"); |
|
76 |
- # Gitprep::Util::run_command(@git_checkout_tmp_branch) |
|
77 |
- # or Carp::croak "Can't execute git checkout: @git_checkout_tmp_branch"; |
|
74 |
+ my $gitprep_tmp_branch_name = '__gitprep_tmp_branch__'; |
|
75 |
+ |
|
76 |
+ # Checkout tmp branch and git reset --hard from my remote branch |
|
77 |
+ my @git_checkout_tmp_branch = $self->app->git->cmd( |
|
78 |
+ $work_rep_info, |
|
79 |
+ 'checkout', |
|
80 |
+ $gitprep_tmp_branch_name, |
|
81 |
+ ); |
|
82 |
+ Gitprep::Util::run_command(@git_checkout_tmp_branch) |
|
83 |
+ or Carp::croak "Can't execute git checkout: @git_checkout_tmp_branch"; |
|
84 |
+ |
|
85 |
+ # git reset --hard |
|
86 |
+ my @git_reset_hard_cmd = $self->app->git->cmd( |
|
87 |
+ $work_rep_info, |
|
88 |
+ 'reset', |
|
89 |
+ '--hard', |
|
90 |
+ "origin/$from_rev" |
|
91 |
+ ); |
|
92 |
+ Gitprep::Util::run_command(@git_reset_hard_cmd) |
|
93 |
+ or Carp::croak "Can't execute git reset --hard: @git_reset_hard_cmd"; |
|
94 |
+ |
|
78 | 95 |
} |
79 | 96 |
|
80 | 97 |
layout 'common', title => "Comparing $from_rev...$rev \x{30fb} $user/$project"; |