cgit 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +5 -5
  2. data/bin/cgit +66 -4
  3. metadata +6 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: f45fced1af51c1e42f4e3be4c21a7aab54dce3d3
4
- data.tar.gz: e6fb4135b534cd47f290d353f4a9ef834e4dbb02
2
+ SHA256:
3
+ metadata.gz: 1a754fd3e2c9bf61c8ec212036cc1c16d6989721a0db71a2576a94b87c50df52
4
+ data.tar.gz: a4b37f093920bb1fb3fd6e0ad2c3c82dcb6e8ddb723b1e49f5db898ed90442c4
5
5
  SHA512:
6
- metadata.gz: d4abb3b3659b2ce7e5c8fb24654d6c7c3aa3ed63752cc927d8a507d6b406554ceb3cf0404e96b2b1167920e71eff94cbaf5b74e7c3c3f0e7ed26aee8dc40586c
7
- data.tar.gz: ecae2e9cbf10960aeaab346eb5ccdd5d559d01cce6d2427840cb9fd9c0371f8a8c47d8b1ec24649d43aa7141b4f7289816038974330a7229803acf2ab50a9137
6
+ metadata.gz: 27f80ac94ed36775a82d2753213fa0d374bf0af780f82d7808d23a7bad523a5af45b3d7db4dd4575f79bf0af7f3e821e995ececc08d19799539adf6a9324a1c0
7
+ data.tar.gz: c240dc862bb748143256487b72e33ad339c742252cc4fc3cad15d126c3cb7631502023e622ef17c9f7d42d044e3711d92fa98bc70036108f3c821dbd2368a4cf
data/bin/cgit CHANGED
@@ -3,7 +3,7 @@
3
3
  require 'Thor'
4
4
 
5
5
  class CGit < Thor
6
- desc "put MESSAGE", "Adds and commits with a MESSAGE."
6
+ desc "put [MESSAGE]", "Adds and commits with a MESSAGE."
7
7
  method_option :remote, :aliases => "-r", :desc => "Applies this remotely to the current branch."
8
8
  def put(message)
9
9
  system ("git add --a .")
@@ -20,7 +20,7 @@ class CGit < Thor
20
20
  system ("git reset --soft HEAD^")
21
21
  end
22
22
 
23
- desc "retip COMMIT", "Moves the TIP of the current branch"
23
+ desc "retip [COMMIT]", "Moves the TIP of the current branch"
24
24
  method_option :remote, :aliases => "-r", :desc => "Applies this remotely to the current branch."
25
25
  def retip(commit)
26
26
  system ("git reset --hard #{commit}")
@@ -37,13 +37,13 @@ class CGit < Thor
37
37
  git log --pretty=format:\"%h %s\" --graph")
38
38
  end
39
39
 
40
- desc "valid", "Displays unpushed commits to remote in all branches."
40
+ desc "unpushed", "Displays unpushed commits to remote in all branches."
41
41
  def valid
42
42
  puts ("Non pushed commits:")
43
43
  system ("git log --branches --not --remotes --decorate --oneline")
44
44
  end
45
45
 
46
- desc "merge DESTINATION_BRANCH SOURCE_BRANCH", "Pulls latest remote changes on both branches and then merges the SOURCE_BRANCH into the DESTINATION_BRANCH."
46
+ desc "merge [DESTINATION_BRANCH] [SOURCE_BRANCH]", "Pulls latest remote changes on both branches and then merges the SOURCE_BRANCH into the DESTINATION_BRANCH."
47
47
  method_option :remote, :aliases => "-r", :desc => "Pushes the merge remotely to the current branch. Be aware that this will not work if there are conflicts."
48
48
  def merge(destination_branch, source_branch)
49
49
  system ("git checkout #{source_branch}")
@@ -62,6 +62,68 @@ class CGit < Thor
62
62
  end
63
63
  end
64
64
 
65
+ desc "squash [BASE_BRANCH]", "Squashes commits in the current branch and synchronizes with the remote BASE_BRANCH. Commits to squash are selected by comparing the up-to-date remote BASE_BRANCH with the current branch HEAD. Committing the squash may fail if there is a merge conflict. It's recommended to merge with the base branch beforehand if there is a chance of merge conflicts."
66
+ method_option :message, :aliases => "-m", :desc => "Message to override the default squash message. Cannot be used together with title(-t) parameter."
67
+ method_option :title, :aliases => "-t", :desc => "Title for the default squash commit message. Will be followed by a list of messages for each commit. If not specified, the title will be the default. Cannot be used together with message(-m) parameter."
68
+ method_option :remote, :aliases => "-r", :desc => "Pushes the merge remotely to the current branch"
69
+ def squash(base_branch)
70
+ message = options[:message]
71
+ title = options[:title]
72
+
73
+ if message && title
74
+ puts("Please specify only message or title.")
75
+ exit 1
76
+ end
77
+
78
+ system ("git fetch")
79
+ system ("git branch -D cgit_squash_backup")
80
+ system ("git branch cgit_squash_backup")
81
+ system ("git reset --hard origin/#{base_branch}")
82
+ system ("git merge --squash cgit_squash_backup")
83
+
84
+ if message
85
+ system ("git commit -m \"#{message}\"")
86
+ else
87
+ git_dir = `git rev-parse --git-dir`.delete("\n")
88
+ file_path = "#{git_dir}/SQUASH_MSG"
89
+ lines = File.readlines(file_path)
90
+ skip_count = 0
91
+ File.open(file_path, 'w') do |file|
92
+ if title
93
+ file.puts(title)
94
+ else
95
+ file.puts("Squashed commits")
96
+ end
97
+ file.puts("")
98
+
99
+ # Filter and write the commit messages only
100
+ lines.each_with_index do |line, i|
101
+ if skip_count > 0
102
+ skip_count -= 1
103
+ next
104
+ end
105
+ if line.empty? || line == "\n" || i == 0
106
+ next
107
+ end
108
+ if i + 2 < lines.size - 1 &&
109
+ line.start_with?("commit") &&
110
+ lines[i+1].start_with?("Author:") &&
111
+ lines[i+2].start_with?("Date:")
112
+ skip_count = 2
113
+ next
114
+ end
115
+ file.puts("* #{line.strip}")
116
+ end
117
+ end
118
+ system ("git commit --no-edit")
119
+ end
120
+
121
+ remote = options[:remote]
122
+ if remote
123
+ system ("git push origin HEAD")
124
+ end
125
+ end
126
+
65
127
  end
66
128
 
67
129
  CGit.start
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cgit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Wong
@@ -14,14 +14,14 @@ dependencies:
14
14
  name: thor
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: 0.19.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 0.19.1
27
27
  description: Some useful git command line shortcuts
@@ -42,17 +42,16 @@ require_paths:
42
42
  - lib
43
43
  required_ruby_version: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  required_rubygems_version: !ruby/object:Gem::Requirement
49
49
  requirements:
50
- - - '>='
50
+ - - ">="
51
51
  - !ruby/object:Gem::Version
52
52
  version: '0'
53
53
  requirements: []
54
- rubyforge_project:
55
- rubygems_version: 2.0.14
54
+ rubygems_version: 3.0.3
56
55
  signing_key:
57
56
  specification_version: 4
58
57
  summary: Some useful git command line shortcuts