Module: Semmy::Scm::Jj

Extended by:
Jj
Included in:
Jj
Defined in:
lib/semmy/scm/jj.rb

Defined Under Namespace

Classes: BookmarkNotFound, CommandFailed, GitHeadMismatch

Instance Method Summary collapse

Instance Method Details

#attach_git_head(branch) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/semmy/scm/jj.rb', line 38

def attach_git_head(branch)
  bookmark = required_bookmark(branch)
  reference = "refs/heads/#{bookmark}"

  unless git('rev-parse', 'HEAD') == git('rev-parse', reference)
    fail(GitHeadMismatch,
         "Git HEAD is not at #{bookmark}. " \
         "Run `jj new #{bookmark}` before releasing.")
  end

  Shell.info("Attaching git HEAD to #{bookmark}.")
  git('symbolic-ref', 'HEAD', reference)
end

#commit_all(message, branch) ⇒ Object



19
20
21
22
23
24
# File 'lib/semmy/scm/jj.rb', line 19

def commit_all(message, branch)
  bookmark = required_bookmark(branch)

  jj('commit', '--message', message)
  jj('bookmark', 'set', bookmark, '--revision', '@-')
end

#create_branch(name, base) ⇒ Object



26
27
28
# File 'lib/semmy/scm/jj.rb', line 26

def create_branch(name, base)
  jj('bookmark', 'create', name, '--revision', required_bookmark(base))
end

#current_branchObject



12
13
14
15
16
17
# File 'lib/semmy/scm/jj.rb', line 12

def current_branch
  jj('log', '--no-graph',
     '--revisions', 'heads(::@ & bookmarks())',
     '--template', 'local_bookmarks.map(|bookmark| bookmark.name()).join("\n")')
    .split("\n").first
end

#push(remote, name) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/semmy/scm/jj.rb', line 30

def push(remote, name)
  unless bookmark?(name)
    fail(BookmarkNotFound, "Bookmark #{name} does not exist.")
  end

  jj('git', 'push', '--remote', remote, '--bookmark', name)
end